- using (SqlConnection conn = new SqlConnection(constr))
- {
- conn.Open();
- using (SqlCommand cmd = conn.CreateCommand())
- {
- cmd.CommandText = "select * from T_tavle";
-
- DataSet dst = new DataSet();
- SqlDataAdapter adapter = new SqlDataAdapter(cmd);
- adapter.Fill(dst);
-
- DataTable table =dst.Tables[0];
- DataRowCollection rows= table.Rows;
- for(int i=0;i<rows.Count;i++)
- {
- DataRow row =(DataRow)row[i];
- int age=(int)row["age"];
- }
- //foreach(DataRow row in dst.Tables[0].Rows)
- //{
- // int age=(int)row["age"];
- //}
- }
- }
复制代码 将查询的数据存储到dataset的一个方法
|