将多行数据放入数组中

DataTable dt = new DataTable(); OleDbDataReader reader=null; string[] yuan = null; try { string connstr = "Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=Database.mdb"; OleDbConnection conn = new OleDbConnection(connstr); conn.Open(); OleDbCommand cmd = conn.CreateCommand(); cmd.CommandText = "Select yuan From HanZiKu"; reader = cmd.ExecuteReader(); dt.Load(reader); //将reader获取的数据放入DataTable(dt)中 conn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } yuan = new string[dt.Rows.Count]; //实例化数组 长度是dt的长度 for (int i = 0; i < yuan.Length; i++) { yuan[i] = dt.Rows[i][0].ToString(); }

你可能感兴趣的:(exception,String,cmd,null)