问题查找表索引0 [英] Problem finding table index 0
本文介绍了问题查找表索引0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
再次向我问好.
代码在查找索引为0(零)的表时遇到了一些问题
我只用一张桌子就看不到自己的问题.
这是我的更新功能的代码:
hey guys me again.
got a little problem with the code finding the table with the index of 0 (zero)
i dont see the problem my self as i am using only one table.
this is the code for my update function:
private void UpdateBTN_Click(object sender, EventArgs e)
{
using (conn)
{
da.UpdateCommand = new SqlCommand("UPDATE Book SET Title = @title, AuthorFirstName = @authorFirstName, AuthorSurname = @authorsurname, AquisitionDate = @aquisitiondate, PublisherName = @publishername,
PublisherCity = @publishercity, PublishingDate = @publishingdate,
ISBN = @isbn, DDClassification = @ddclassification WHERE BookID = @ID", conn);
da.UpdateCommand.Parameters.Add("@title", SqlDbType.VarChar).Value = titleTB.Text;
da.UpdateCommand.Parameters.Add("@authorFirstName", SqlDbType.VarChar).Value = authorFirstNameTB.Text;
da.UpdateCommand.Parameters.Add("@authorsurname", SqlDbType.VarChar).Value = authorSurNameTB.Text;
da.UpdateCommand.Parameters.Add("@aquisitiondate", SqlDbType.Date).Value = aquisitionDateTB.Text.ToString();
da.UpdateCommand.Parameters.Add("@publishername", SqlDbType.VarChar).Value = publisherNameTB.Text;
da.UpdateCommand.Parameters.Add("@publishercity", SqlDbType.VarChar).Value = publisherCityTB.Text;
da.UpdateCommand.Parameters.Add("@publishingdate", SqlDbType.Date).Value = publishingDateTB.Text.ToString();
da.UpdateCommand.Parameters.Add("@isbn", SqlDbType.VarChar).Value = ISBNTB.Text;
da.UpdateCommand.Parameters.Add("@ddclassification", SqlDbType.VarChar).Value = DDClassificationTB.Text;
da.UpdateCommand.Parameters.Add("@ID", SqlDbType.Int).Value = ds.Tables[0].Rows[tblNamesBS.Position][0];// right here @ ds.Tables[0]
conn.Open();
da.UpdateCommand.ExecuteNonQuery();
}
}
错误是最后一个更新参数,是否知道为什么会引发此异常?
消息是:
未处理IndexOutOfRangeException
找不到表0.
问候
Matt.
error is on last update parameter, any idea why it is throwing this exception?
message is:
IndexOutOfRangeException was unhandled
Cannot find table 0.
Regards
Matt.
推荐答案
ds在代码中的那一点不包含表,这似乎是您的问题.
ds contains no tables at that point in the code, that seems to be your problem.
da.UpdateCommand.Parameters.Add("@ ID",SqlDbType.Int).Value = ds.Tables [0] .Rows [tblNamesBS.Position] [0];//在这里@ ds.Tables [0]
ds.Tables[0]
处有错误
使用Visual Studio DEBUGGER并检查数据集包含什么.是否有任何表.显然其中没有表.
我看不到上述方法中定义的ds
.因此,请确保每当您填充数据集时,该数据都将保留下来,并确保在使用它的值之前,您要检查表计数.
da.UpdateCommand.Parameters.Add("@ID", SqlDbType.Int).Value = ds.Tables[0].Rows[tblNamesBS.Position][0];// right here @ ds.Tables[0]
There is error atds.Tables[0]
Use Visual Studio DEBUGGER and check what does the dataset contains. If there is any table in it or not. Clearly there is no table in it.
I don''t see ads
defined in the above method. So, make sure whenever you are filling your dataset, it persists and make sure that before using it''s value you check for table count.
我自己解决了这个问题,我在传递一个空值数据集:(,
早点注意到了.感谢您的答复
fixed this myself, i was passing an empty dataset :(,
noticed it earlier. thanks for reply''s much appreciated
这篇关于问题查找表索引0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文