hi for all i have problem in my application i try on it for two days first off i make procedure in database i sure of it procedure hasn't problem after that i make function in bll class
public static DataTable getbyidBLL(ClsresempDAL obj)
{
try
{
string _spName1 = "ResEmp"; // storedprocedure name
string _mode = "getbyid"; // Method name in storedprocedure
DBBridge objDBBridge = new DBBridge();//
SqlParameter[] param = new SqlParameter[2];
param[0] = new SqlParameter("@id", obj.Emp_ID);
param[1] = new SqlParameter("@mode", _mode);
DataTable ds = new DataTable();
ds = objDBBridge.ExecuteDataset(_spName1, param).Tables[0];
return ds;
}
catch (Exception exp)
{
// clsErrorLog.log_error(exp);
DataTable ds = new DataTable();
return ds;
}
}
your result doesn't contain any records hence the message. If you try out the stored procedure in SQL Server Management Studio, does it return something? If not optimize it and try again.
Grz, Kris.
Read my blog | Twitter Interested in Azure, ASP.NET (MVC), jQuery, WCF, EF, MS SQL, ...
Keep the forums clean: report to the moderation team!
Most likely as otherwise your application would run.
If you place a breakpoint on this line: ds = objDBBridge.ExecuteDataset(_spName1,
param).Tables[0];
and run your application, does it retrieve information or does it error out already? Try to find the line where things go wrong with stepping through/into the code and then work around that problem.
Grz, Kris.
Read my blog | Twitter Interested in Azure, ASP.NET (MVC), jQuery, WCF, EF, MS SQL, ...
Keep the forums clean: report to the moderation team!
You have to check whether the DataSet has more than one DataTable,and check whether one DataTable has more than one DataRow by using the "if" statement:
【Solution】
public static DataTable getbyidBLL(ClsresempDAL obj)
{
try
{
string _spName1 = "ResEmp"; // storedprocedure name
string _mode = "getbyid"; // Method name in storedprocedure
DBBridge objDBBridge = new DBBridge();//
SqlParameter[] param = new SqlParameter[2];
param[0] = new SqlParameter("@id", obj.Emp_ID);
param[1] = new SqlParameter("@mode", _mode); DataTable dt = null; DataSet ds = objDBBridge.ExecuteDataset(_spName1, param); if(ds.Tables>0) { dt = ds.Tables[0];
return dt; }
throw new Exception("No Tables Found!"); }
catch (Exception exp)
{
// clsErrorLog.log_error(exp);
DataTable ds = new DataTable();
return ds;
}
}
public void getbyid()
{
DataTable dt = new DataTable();
dt = ClsResEmpBLL.getbyidBLL(this);
DataRow dr = null; if(dt.Rows.Count>0) { dr = dt.Rows[0];
mr.crazy
Member
34 Points
79 Posts
There is no row at position 0
Apr 29, 2012 07:49 AM|LINK
hi for all i have problem in my application i try on it for two days first off i make procedure in database i sure of it procedure hasn't problem after that i make function in bll class
public static DataTable getbyidBLL(ClsresempDAL obj) { try { string _spName1 = "ResEmp"; // storedprocedure name string _mode = "getbyid"; // Method name in storedprocedure DBBridge objDBBridge = new DBBridge();// SqlParameter[] param = new SqlParameter[2]; param[0] = new SqlParameter("@id", obj.Emp_ID); param[1] = new SqlParameter("@mode", _mode); DataTable ds = new DataTable(); ds = objDBBridge.ExecuteDataset(_spName1, param).Tables[0]; return ds; } catch (Exception exp) { // clsErrorLog.log_error(exp); DataTable ds = new DataTable(); return ds; } }and then i call it in DAL class
public void getbyid() { DataTable dt = new DataTable(); dt = ClsResEmpBLL.getbyidBLL(this); DataRow dr = dt.Rows[0]; Emp_ID = int.Parse(dr["Emp_ID"].ToString()); ResEmpCivilID = int.Parse(dr["ResEmpCivilID"].ToString()); ResEmpName = dr["ResEmpName"].ToString(); Grade = int.Parse(dr["Grade"].ToString()); PerTypeID = dr["PerTypeID"].ToString(); SectionID = int.Parse(dr["SectionID"].ToString()); User_name = dr["user_name"].ToString(); }then in gridview row command i add this code
f (e.CommandName.ToString() == "edit0") { cc.Emp_ID = int.Parse(e.CommandArgument.ToString()); cc.getbyid(); }when i execute the error message appear to me There is no row at position 0. in getbyid in dal class any one can help me
thanks
XIII
All-Star
182704 Points
23463 Posts
ASPInsiders
Moderator
MVP
Re: There is no row at position 0
Apr 29, 2012 07:58 AM|LINK
Hi,
your result doesn't contain any records hence the message. If you try out the stored procedure in SQL Server Management Studio, does it return something? If not optimize it and try again.
Grz, Kris.
Interested in Azure, ASP.NET (MVC), jQuery, WCF, EF, MS SQL, ...
Keep the forums clean: report to the moderation team!
mr.crazy
Member
34 Points
79 Posts
Re: There is no row at position 0
Apr 29, 2012 08:23 AM|LINK
friend i'm sure of stored procedure i try it many times
is there another problem
XIII
All-Star
182704 Points
23463 Posts
ASPInsiders
Moderator
MVP
Re: There is no row at position 0
Apr 29, 2012 08:37 AM|LINK
Hi,
Most likely as otherwise your application would run.
If you place a breakpoint on this line: ds = objDBBridge.ExecuteDataset(_spName1, param).Tables[0];
and run your application, does it retrieve information or does it error out already? Try to find the line where things go wrong with stepping through/into the code and then work around that problem.
Grz, Kris.
Interested in Azure, ASP.NET (MVC), jQuery, WCF, EF, MS SQL, ...
Keep the forums clean: report to the moderation team!
mr.crazy
Member
34 Points
79 Posts
Re: There is no row at position 0
Apr 29, 2012 10:22 AM|LINK
i try friend it retrives data with the line you select
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: There is no row at position 0
May 01, 2012 12:53 AM|LINK
Hello mr.crazy:)
You have to check whether the DataSet has more than one DataTable,and check whether one DataTable has more than one DataRow by using the "if" statement:
【Solution】
public static DataTable getbyidBLL(ClsresempDAL obj)
{
try
{
string _spName1 = "ResEmp"; // storedprocedure name
string _mode = "getbyid"; // Method name in storedprocedure
DBBridge objDBBridge = new DBBridge();//
SqlParameter[] param = new SqlParameter[2];
param[0] = new SqlParameter("@id", obj.Emp_ID);
param[1] = new SqlParameter("@mode", _mode);
DataTable dt = null;
DataSet ds = objDBBridge.ExecuteDataset(_spName1, param);
if(ds.Tables>0)
{
dt = ds.Tables[0];
return dt;
}
throw new Exception("No Tables Found!");
}
catch (Exception exp)
{
// clsErrorLog.log_error(exp);
DataTable ds = new DataTable();
return ds;
}
}
public void getbyid()
{
DataTable dt = new DataTable();
dt = ClsResEmpBLL.getbyidBLL(this);
DataRow dr = null;
if(dt.Rows.Count>0)
{
dr = dt.Rows[0];
Emp_ID = int.Parse(dr["Emp_ID"].ToString());
ResEmpCivilID = int.Parse(dr["ResEmpCivilID"].ToString());
ResEmpName = dr["ResEmpName"].ToString();
Grade = int.Parse(dr["Grade"].ToString());
PerTypeID = dr["PerTypeID"].ToString();
SectionID = int.Parse(dr["SectionID"].ToString());
User_name = dr["user_name"].ToString();
}
else
{
throw new Exception(……);
}
}
mr.crazy
Member
34 Points
79 Posts
Re: There is no row at position 0
May 02, 2012 05:24 AM|LINK
freind the problem here in this code
else{ throw new Exception("no result"); }error message is no result
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: There is no row at position 0
May 02, 2012 05:26 AM|LINK
What does that mean?Do you mean you've thrown an exception manually?
tusharrs
Contributor
3230 Points
668 Posts
Re: There is no row at position 0
May 02, 2012 05:33 AM|LINK
error is at this line
if (dt.Rows.Count>0
{
DataRow dr = dt.Rows[0];
// and remaining statements
}
as there are no rows in datatable it is throwing error while retreiving row at zero index
( Mark as Answer if it helps you out )
View my Blog
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: There is no row at position 0
May 02, 2012 05:37 AM|LINK
Feeling interested and curious——Since I've checked dt.Rows.Count>0,how cannot fetch dt.Rows[0]?