我把数据库里的数据转成C#.net中的二维数组,大家看看我写的对不对?
SqlConnection con = new SqlConnection();
string strcon;
strcon = "Data Source=\\SQLEXPRESS;Initial Catalog=mydata;uid=sa;pwd=19870201";
con.ConnectionString = strcon;
con.Open();
string strSQL = "SELECT * FROM jihuadata "; //要执行的SQL语句
SqlDataAdapter da = new SqlDataAdapter(strSQL, con); //创建DataAdapter数据适配器实例
DataSet ds = new DataSet();//创建DataSet实例
da.Fill(ds, "jihuadata");
for (int j = 0; j < ds.Tables[0].Rows.Count - 1; j++)
for (int i = 0; i < ds.Tables[0].Columns.Count - 1; i++)
{
string columnName = ds.Tables[0].Columns[i].Caption;
string value = ds.Tables[0].Rows[j][columnName].ToString();
}
怎样在这里写一段循环输出的函数,希望大家给些意见!
------解决方案--------------------datarow貌似有个方法是ToArray()
------解决方案--------------------
------解决方案--------------------
int row = data.Rows.Count;
int column = data.Columns.Count;
string[,] tb = new string[row, column];
for (int i = 0; i < row - 1; i++)
{
for (int j = 0; j < column - 1; j++)
{
tb[i, j] = data.Rows[i][j].ToString();
}
}