本文介绍了请帮我修复此错误(在列表框中显示)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是错误>

**************例外文字**************

System.ArgumentOutOfRangeException:InvalidArgument ='0'的值对'SelectedIndex'无效。

参数名称:SelectedIndex



我的代码>



here is the error>
************** Exception Text **************
System.ArgumentOutOfRangeException: InvalidArgument=Value of '0' is not valid for 'SelectedIndex'.
Parameter name: SelectedIndex

my code>

DataSet st = new DataSet();
           string strConnectionString = "Data Source=JAMES-PC\\SQLEXPRESS;Initial Catalog=staff;Integrated Security=True";

           SqlConnection objconnection = new SqlConnection(strConnectionString);
           using (SqlCommand cmd = new SqlCommand("SELECT  [name] FROM [staff1]",
           objconnection))
           {
               using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
               {
                   adapter.Fill(st);
               }
           }

           var empList = st.Tables[0].AsEnumerable().Select(dataRow =>

           dataRow.Field<string>("name")).ToList();

           listBox1.SelectedIndex = 0;
           listBox1.Update();



我不明白这个问题。它在10分钟前工作但现在却没有?我真的很困惑任何帮助都是apreciated


I dont understand the issue.It worked 10 mins ago but now it doesn't? I am really confused any help would be apreciated

推荐答案


这篇关于请帮我修复此错误(在列表框中显示)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 00:57