本文介绍了索引超出了阵列自动售货机的范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在对自动售货机进行编程,并且查询的是用于从自动售货机中选择产品的按钮,感谢您的帮助.价格,产品和产品编号都是数据库的一部分.

 私有  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(" 从产品ID为1"的产品中选择价格);

       }
解决方案



So I am programming a vending machine and the query is for a button to select a product from the vending machine, any help is appreciated. Price, products and productid are all part of the database.

private void runQurey(String query)
       {
           OleDbCommand cmd = new OleDbCommand(query, conn);
           OleDbDataReader cusReader = cmd.ExecuteReader();

           lblprice.Text = "";
           lblquantity.Text = "";

           while (cusReader.Read())
           {
               lblprice.Text = cusReader.GetValue(0).ToString();
               lblquantity.Text = cusReader.GetValue(1).ToString();
           }
       }

       private void btnselect1_Click(object sender, EventArgs e)
       {
           runQurey("SELECT Price FROM Products WHERE ProductID = 1");

       }
解决方案




这篇关于索引超出了阵列自动售货机的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 13:08