Click here to Skip to main content
15,889,879 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
            return;
        try
        {
            trActivity.Visible = false;
            btnSave.Visible = false;
            btnCancel.Visible = false;

            DateTime dtDate = DateTime.Now.AddDays(-10);
            string strFromDate = dtDate.Day  + "," + dtDate.Month + "," + dtDate.Year;
            string strToDate = DateTime.Now.Day + "," + DateTime.Now.Month + "," + DateTime.Now.Year;

            txtentrydate.Attributes.Add("onfocus", "showCalendarControl(this,'" + strFromDate + "-" + strToDate + "')");
            DataSet ds = _objTC.GetEmployeeLevelID(Session["id"].ToString(), Convert.ToInt32(Session["schoolAcaID"].ToString()));
            int LevelID = Convert.ToInt32(ds.Tables[0].Rows[0]["LevelID"].ToString());
            ViewState["LevelID"] = LevelID;
            string strDay = DateTime.Now.Day.ToString();
            string strMonth = DateTime.Now.Month.ToString();
            string strYear = DateTime.Now.Year.ToString();
            strDay = strDay.Length < 2 ? "0" + strDay : strDay;
            strMonth = strMonth.Length < 2 ? "0" + strMonth : strMonth;
            txtentrydate.Text = strMonth + "-" + strDay + "-" + strYear;
           }
        catch (Exception ex)
        {
            Log.Message(ex);
        }
    }


What I have tried:

public DataSet GetEmployeeLevelID(string EmployeeID, int SchoolAcaID)
  {
      DataSet ds = new DataSet();
      try
      {
          cmd = new SqlCommand("Sms_GetEmployeeLevelID", dAL.con);
          cmd.CommandType = CommandType.StoredProcedure;
          cmd.Parameters.AddWithValue("@EmployeeID", EmployeeID);
          cmd.Parameters.AddWithValue("@Schoolacaid", Schoolacaid);
          SqlDataAdapter sqlDA = new SqlDataAdapter(cmd);
          sqlDA.Fill(ds);
      }
      catch (Exception ex)
      {
          Log.Message(ex.ToString());
      }
      return ds;
  }
//this is my stored procedure appcode file
Posted
Updated 28-Feb-22 8:06am

We can't tell: we have no access to your DB, the data it holds, the stored procedure you are calling, or the values you pass to it as parameters. And you need all of that while your code is running (which we can't do in isolation) to begin working out what might be wrong.
Obviously, there is nothing being returned by the call - but we have no idea why not and no way to find out.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
I'm pretty sure that the error is occured in this line:
C#
int LevelID = Convert.ToInt32(ds.Tables[0].Rows[0]["LevelID"].ToString());


I'd check if ds.Tables[0] contains any row:
if (ds.Tables[0].Rows.Count > 0)
//your logic here...
 
Share this answer
 
This is very simple and clear in you error message, there is no results were returned from your query. You should apply check before going to access value from table rows.
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
	int LevelID = Convert.ToInt32(ds.Tables[0].Rows[0]["LevelID"].ToString());
	ViewState["LevelID"] = LevelID;               
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900