索引超出了阵列自动售货机的范围 [英] Index was outside the bounds of the array vending machine
本文介绍了索引超出了阵列自动售货机的范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我正在对自动售货机进行编程,并且查询的是用于从自动售货机中选择产品的按钮,感谢您的帮助.价格,产品和产品编号都是数据库的一部分.
私有 void runQurey(字符串查询)
{
OleDbCommand cmd = 新 OleDbCommand(query,conn);
OleDbDataReader cusReader = cmd.ExecuteReader();
lblprice.Text = " ;
lblquantity.Text = " ;
同时(cusReader.Read())
{
lblprice.Text = cusReader.GetValue( 0 ).ToString();
lblquantity.Text = cusReader.GetValue( 1 ).ToString();
}
}
私有 无效 btnselect1_Click(对象发件人,EventArgs e)
{
runQurey(" );
}
解决方案
好吧...您正在从数据库中请求一列:
runQurey(" );
然后尝试处理两列:
lblprice.Text = cusReader.GetValue( 0 ).ToString(); lblquantity.Text = cusReader.GetValue( 1 ).ToString();
我怀疑您想返回更多列,因此请尝试执行以下操作:
runQurey("解决方案Well...you are requesting one column from your DB:
runQurey("SELECT Price FROM Products WHERE ProductID = 1");
And then trying to process two columns:
lblprice.Text = cusReader.GetValue(0).ToString(); lblquantity.Text = cusReader.GetValue(1).ToString();
I suspect you want to return more columns, so try something like:
runQurey("SELECT Price, Quantity FROM Products WHERE ProductID = 1");
your query is not correct,bcoz u didn''t take quantity value from ur table but u r bindinding quantity value from reader .Ur datareader is holding only price alone not quantity value
Your query is not right.Add 2 columns name if you want two value in select query.
这篇关于索引超出了阵列自动售货机的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文