选择组合框时出现此错误“索引0为负数或高于行数。” [英] Got this error while selecting a combobox "Index 0 is either negative or above rows count."

查看:94
本文介绍了选择组合框时出现此错误“索引0为负数或高于行数。”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void comboPrtn_SelectionChangeCommitted(object sender, EventArgs e)
       {




           ////---------------------------Show price-------------------

               SqlDataAdapter ddamtp = new SqlDataAdapter("select * from assign_price('" + this.comboPrtn.SelectedValue + "')", con);
               DataSet ddsamtp = new DataSet();
               ddamtp.Fill(ddsamtp, "price");
               DataView vddamtp = new DataView(ddsamtp.Tables["price"]);
               txtUprice.Text = vddamtp[0]["PRICE"].ToString();

           ////----------------------------end-------------------------
       }

推荐答案

自,据我所知 0 不是负数,并且它不能高于行数,这样的消息是完全错误的。

- Carlo The NitPick



但是你的代码也错了(索引相等行数):

Since, as far as I know 0 is not negative, and it can't be either above the rows count, such message is plain wrong.
--Carlo The NitPick

However your code is wrong too (the index is equal to row count):
txtUprice.Text = vddamtp[0]["PRICE"].ToString();



您正在访问 vddamtp [0] 而不确定此类数据视图是否包含至少一行。


You are accessing vddamtp[0] without being sure such dataview contains, at least, one row.


假设 assign_price 是您创建的函数,您需要确保它返回一些值。如果没有,那么行:
Assuming assign_price is a function you created, you need to be sure it returns some values. If it doesn't, then the the line:
txtUprice.Text = vddamtp[0]["PRICE"].ToString();

将给出您引用的异常。


这篇关于选择组合框时出现此错误“索引0为负数或高于行数。”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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