把数据库的数据副给数组的问题

来源:百度知道 编辑:UC知道 时间:2024/06/16 09:37:27
private void button1_Click(object sender, EventArgs e)
{double[] xx =new double[10];int i;
SqlConnection connection = new SqlConnection("server=haha\\SQLEXPRESS;Initial Catalog=ss;Integrated security = sspi");
connection.Open();
SqlCommand command = connection.CreateCommand();
command.CommandText = "SELECT idi FROM [sheet]";
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
xx[i]= [reader("idi")];
}
for(int j=0;j<xx.Length;j++){ richTextBox1.Text += xx[j].ToString();
}
reader.Close();
connection.Close();}
}

为什么不对呀

不懂JAVA,问个VB或ASP的我来试试^
呵呵
玩笑
楼下的回答

把你程序里面的while语句修改一下:

i=0;
while (reader.Read())
{
xx[i++]= [reader("idi")];
}

明白没有,你以前是xx[i],每天记录都赋予数组的第一个元素了,我给改为xx[i++]。同时前面增加i=0的语句。