标签:
DataSet是ADO.Net的中心概念。可以把DataSet当成内存中的数据库,DataSet是不依赖于数据库的独立数据集合。(来自百度百科)
1 using(SqlConnection conn = new SqlConnection("Data Source=PC201507182002\\SQLEXPRESS;Initial Catalog=123456;Integrated Security=True")) 2 { 3 conn.Open(); 4 using (SqlCommand cmd = conn.CreateCommand()) 5 { 6 cmd.CommandText = "select * from student where name =@name"; 7 cmd.Parameters.Add(new SqlParameter("@name",textBox1.Text)); 8 SqlDataAdapter da = new SqlDataAdapter(cmd); 9 DataSet ds = new DataSet(); 10 da.Fill(ds); 11 12 DataTable dt = ds.Tables[0]; 13 DataRowCollection rows = dt.Rows; 14 for (int i = 0; i < rows.Count; i++) 15 { 16 DataRow dr = rows[i]; 17 string name = (string)dr[0]; 18 string name1 = (string)dr[1]; 19 20 MessageBox.Show("name:"+name+"----name1:"+name1); 21 } 22 23 24 } 25 }
标签:
原文地址:http://www.cnblogs.com/kaolalovemiaomiao/p/4707553.html