reader 是一行记录,这样没必要使用DataGrid, 如果要使用DataGrid,那么就使用Dataset ,方法如下 : 首先取得数据,放到DataGrid里System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection("server=localhost;database=northWind;uid=sa;password=110"); conn.Open(); System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter("select * from student",conn); dt = new System.Data.DataSet(); da.Fill(dt,"student");然后绑定数据集和DataGrid DataGrid.SetDataBinding(dt,"student");
我现在做的就是一定要用SqlDataReader 对于DataSet我也想过,实现起来不难
this.textBox1.Text = reader.GetString(0);
朋友 当你用SqlDataReader 得 话 不要忘记 用while{} while { this.textBox1.Text=reader[0].ToString(); }
朋友 当你用SqlDataReader 得 话 不要忘记 用while{} while { this.textBox1.Text=reader[0].ToString(); }
如果要使用DataGrid,那么就使用Dataset ,方法如下 :
首先取得数据,放到DataGrid里System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection("server=localhost;database=northWind;uid=sa;password=110");
conn.Open();
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter("select * from student",conn);
dt = new System.Data.DataSet();
da.Fill(dt,"student");然后绑定数据集和DataGrid
DataGrid.SetDataBinding(dt,"student");
对于DataSet我也想过,实现起来不难
当你用SqlDataReader 得 话 不要忘记 用while{}
while
{
this.textBox1.Text=reader[0].ToString();
}
当你用SqlDataReader 得 话 不要忘记 用while{}
while
{
this.textBox1.Text=reader[0].ToString();
}