C#读取SQL多个关键词数据后将结果存入数组中,如何实现?

2024-11-15 14:24:05
推荐回答(2个)
回答(1):

float[] array_t = new float[12];
int i=0;
SqlConnection sqlconnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
sqlconnection.Open();
SqlCommand sqlcommand = new SqlCommand("SELECT * FROM table");
SqlDataReader reader = sqlcommand.ExecuteReader(CommandBehavior.CloseConnection);
if (reader.Read())
{
array_t [0][i] = float.Parse((reader["a"]).ToString());
array_t [1][i] = float.Parse((reader["b"]).ToString());
array_t [2][i] = float.Parse((reader["c"]).ToString());
i++;
}

回答(2):

为何要放二维数组,还有你怎么读的sql?