一维数组(查询的数据保存到数组)
string[] arr1 = new string[Data.GetDataSet(Data.sqlstr).Tables[0].Rows.Count]; for (int i = 0; i < Data.GetDataSet(Data.sqlstr).Tables[0].Rows.Count; i++) { arr1[i] = Data.GetDataSet(Data.sqlstr).Tables[0].Rows[i][1].ToString(); } foreach (string a2 in arr1) { HttpContext.Current.Response.Write(a2); }
多维数组
public static string[,] QueryUsers(string uname) { //一维数组 //string[] arr1 = new string[Data.GetDataSet(Data.sqlstr).Tables[0].Rows.Count]; //for (int i = 0; i < Data.GetDataSet(Data.sqlstr).Tables[0].Rows.Count; i++) { // arr1[i] = Data.GetDataSet(Data.sqlstr).Tables[0].Rows[i][1].ToString(); //} //调用 //string[,] aaa = userinfo.QueryUsers("ok161"); //foreach (string bb in aaa) //{ // Response.Write(bb); //} Data.sqlstr = "select * from sms_001 where username='" + uname + "'"; //if (Data.GetDataSet(Data.sqlstr).Tables[0].Rows.Count <= 0) { // break; //} int count = Data.GetDataSet(Data.sqlstr).Tables[0].Rows.Count; //二维数组 string[,] arr1 = new string[count, 6]; for (int i = 0; i < count; i++) { DataRow row =Data.GetDataSet(Data.sqlstr).Tables[0].Rows[i]; arr1[i, 0] = row[0].ToString(); arr1[i, 1] = row[1].ToString(); arr1[i, 2] = row[2].ToString(); arr1[i, 3] = row[3].ToString(); arr1[i, 4] = row[4].ToString(); arr1[i, 5] = row[5].ToString(); } return arr1; }