位置0没有行. [英] Thereis no row at position 0.

查看:72
本文介绍了位置0没有行.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么给出错误在位置0处没有行.
?

我的代码在下面


Why the error is giving There is no row at position 0.
?

My code is given below


void submit(Object s, EventArgs e)
{
con.Open();
if((File1.PostedFile!=null)&&(File1.PostedFile.ContentLength>0))
{
fn=System.IO.Path.GetFileName(File1.PostedFile.FileName);
fn=txtName.Text.Trim()+fn;
SaveLocation=Server.MapPath("~/Upload/"+fn);
txtPhoto.Text=SaveLocation;
}
else
{
string v=Request.QueryString["value1"];
ds=new DataSet();
string sql="select photo FROM joining where refno='" + v +"' ";
da=new OleDbDataAdapter(sql,con);
da.Fill(ds,"joining");
DataRow dRow=ds.Tables["joining"].Rows[0];
txtPhoto.Text=dRow["photo"].ToString();
}
com=con.CreateCommand();
if(con!=null)
{
com.CommandText="UPDATE joining SET aname = '" + txtName.Text.Trim() + "',fathname='" + txtFather.Text.Trim() + "',dob='" + txtDOB.Text.Trim() + "',pob='" + txtPOB.Text.Trim() +"',add1='" + txtAdd.Value + "',mob='" + txtMob.Text.Trim() + "',city='" + txtCity.Text.Trim() + "',state='" + txtState.Text.Trim() + "',pcode='" + txtPCode.Text.Trim() + "',panno='" + txtPAN.Text.Trim() + "',nominee='" + txtNominee.Text.Trim() + "',relation='" + txtRelation.Text.Trim() + "',photo='" + txtPhoto.Text.Trim() + "',bank='" + txtBank.Text.Trim() + "',branch='" + txtBranch.Text.Trim() + "',account='" + txtAccount.Text.Trim() + "',acctype='" + ddAccType.SelectedItem.Text + "',intby='" + txtIntro.Text.Trim() + "',codno='" + txtCodno.Text.Trim() + "',agent='" + txtACode.Text.Trim() + "',point='" + txtPoints.Text.Trim() + "' where refno='" + txtRefNo.Text.Trim() + "'";
try{int count=com.ExecuteNonQuery();
System.Web.UI.WebControls.Label lbl1=new System.Web.UI.WebControls.Label();
lbl1.ForeColor=System.Drawing.Color.Yellow;
lbl1.BackColor=System.Drawing.Color.Blue;
lbl1.Text = "Your record UPDATED sucessfully";
ph1.Controls.Add(lbl1);
}
catch(Exception ex)
{
Response.Write(ex.Message);
}}
con.Close();


}

推荐答案

希望下面的代码给出错误

Hi, Hopefully below code is giving error

DataRow dRow=ds.Tables["joining"].Rows[0];





string sql="select photo FROM joining where refno='" + v +"' "; is not giving any result and you are using directly Rows[0], first check if Rows.Count greater than 0 then write your code.



它将解决您的问题.

如果解决了您的问题,别忘了标记. :)



It will solve your problem.

Don''t forget to mark, if it solves your problem. :)


由于数据库表未返回任何记录而出现错误.
您应该先检查行是否为空.
这是代码:
如果(ds.Tables.Count> 0){
如果(ds.Tables [0] .Rows.Count> 0){
DataRow dRow = ds.Tables ["joining"].Rows [0];

....
....
}
}
Error is coming due to no record returned from database table.
You should check first if row is empty or not.
Here is the code:
If (ds.Tables.Count > 0 ){
If (ds.Tables[0].Rows.Count > 0){
DataRow dRow=ds.Tables["joining"].Rows[0];

....
....
}
}


此错误最有可能是由于您构造的SQL语句不产生任何行的事实.
This error is most likely due to the fact that the SQL statement you constructed does not yield any rows.
string sql="select photo FROM joining where refno='" + v +"' ";



这将产生类似以下内容的内容:select photo FROM joining where refno=''xxxxxx''其中xxxxxx是一些合适的值,表joining中具有记录. 注意事项:请不要以这种方式构造您的SQL,因为它会使您的代码容易受到SQL注入攻击的攻击.使用SQLParameter参数化您的SQL语句.这将带来更多好处,因为您不必处理正确的格式和转义内容.

问候,

曼弗雷德(Manfred)



This would yield something like: select photo FROM joining where refno=''xxxxxx'' where xxxxxx is some suitable value for which there are records in table joining. Caveat: Please do not construct your SQL in such a fashion as it leaves your code vulnerable to SQL injection attacks. Use SQLParameter to parameterize your SQL statements. This will be of added benfit as you will not have to deal with proper formatting and escaping stuff.

Regards,

Manfred


这篇关于位置0没有行.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆