Click here to Skip to main content
15,881,828 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

I got a Problem, when i set the debug = true in the web.config the projects works fine,but when i set debug = false in the web.config then i got a server error that

There is no row at position 0.


here is the code lines

C#
InternalLinkBL bl = new InternalLinkBL(SessionContext.SystemUser);
               RowId = URLMessage.GetParam(PageCode, 0);
               bl.Fetch(ds, RowId);
               if (ds.Tables[bl.SqlEntityX].Rows.Count > 0)
               {

                   Response.Redirect("~/Login/Login.aspx?" + "ReturnURL=" + Request.Url.ToString());
               }


I checked procedure it's working fine, table got the content, parameters are passed, data fetches but still it shows this error.

thanks
Posted
Updated 8-Mar-21 7:04am
v3
Comments
Prasanta_Prince 25-Apr-11 3:09am    
Normally this error occurs when datatable is empty.
Pravin Patil, Mumbai 25-Apr-11 4:12am    
and it has got nothing to do with Debug value in Web.config.
koolprasad2003 25-Apr-11 6:44am    
This error has nothing to do with Web.config. Actually when you have try to fecth value from empty dataset this error thrown

1 solution

You will get this error normally if your datasource doesn't contains any records. Check the data of the dataset ds in your code while tracing. Always check the dataset before comparison like below.
C#
bl.Fetch(ds, RowId);
if (ds!= null)//Check if the dataset is null
{
 if (ds.Tables.Count > 0)//Check if the dataset contains Table
 {
  if (ds.Tables[bl.SqlEntityX].Rows.Count > 0)
  {
      Response.Redirect("~/Login/Login.aspx?" + "ReturnURL=" + Request.Url.ToString());
  }
 }
}
else
{
     Response.Redirect("No data");//Give appropriate message here
}


BTW Check that can you get values for RowId & also the Fetch() too.
 
Share this answer
 
Comments
Sandeep Mewara 25-Apr-11 8:29am    
My 5!
Member 9962877 11-Apr-13 0:36am    
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{

SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=admin;database=projeval");
SqlCommand cmd = new SqlCommand();
SqlCommand cmd1 = new SqlCommand();
SqlCommand cmd2 = new SqlCommand();
SqlCommand cmd3 = new SqlCommand();
SqlDataAdapter ada = new SqlDataAdapter();
DataTable dt = new DataTable();
DataTable dt1 = new DataTable();
SqlDataAdapter ada3 = new SqlDataAdapter();
DataTable dt3 = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{

cmd.Connection = con;
cmd.CommandText = "select *from logindate";
ada.SelectCommand = cmd;
ada.Fill(dt);
if (dt.Rows[0][0].ToString() == DateTime.Now.ToShortDateString())
{
Literal1.Visible = true;
}
else
{
Literal1.Visible = false;
}


}
}
protected void Button1_Click(object sender, EventArgs e)
{
cmd.Connection = con;
cmd.CommandText = "sp_login";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@uname", TextBox1.Text);
cmd.Parameters.AddWithValue("@pwd", TextBox2.Text);
SqlParameter p = new SqlParameter("@val", SqlDbType.Int);
p.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(p);
SqlParameter p1 = new SqlParameter("@uid", SqlDbType.Int);
p1.Direction = ParameterDirection.Output;
cmd.Parameters.Add(p1);
SqlParameter p2 = new SqlParameter("@type", SqlDbType.VarChar ,90);
p2.Direction = ParameterDirection.Output;
cmd.Parameters.Add(p2);
con.Open();
cmd.ExecuteNonQuery();
con.Close();


if(p.Value.ToString()=="1")
{
Session["uid"]=p1.Value.ToString();
Session["type"] = p2.Value.ToString();
switch(p2.Value.ToString())
{
case "student":
dt.Clear();
cmd1.Connection = con;
cmd1.CommandText = "select * from login where uid=" + p1.Value.ToString();
ada.SelectCommand = cmd1;
ada.Fill(dt);
if (dt.Rows[0][4].ToString() == "yes")
{
cmd2.Connection = con;
cmd2.CommandText = "select grpname from grouplogin where uid=" + p1.Value.ToString();
ada.SelectCommand = cmd2;
ada.Fill(dt1);
Session["studentgpname"] = dt1.Rows[0][0].ToString();

Response.Redirect("studenthome.aspx");
}
else
{
Label5.Text = "Not approved";
}
con.Open();
cmd1.ExecuteNonQuery();
con.Close();
break;
case "admin":
Response.Redirect("adminhome.aspx");
break;

case "HOD":
Response.Redirect("HodAssignStaff.aspx");
break;
case "Staff":
dt.Clear();
cmd1.Connection = con;
cmd1.CommandText = "select * from login where uid=" + p1.Value.ToString();
ada.SelectCommand = cmd1;
ada.Fill(dt);
if (dt.Rows[0][4].ToString() == "yes")
{
String staff = dt.Rows[0][1].

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