首页上一页 1 下一页尾页 1 条记录 1/1页
小白请教个关于DataGridView控件中显示数据的问题。
发表在C#图书答疑
2015-05-07
是否精华
是
否
版块置顶:
是
否
private void button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server = USER-20150322KM;database = huanghe;uid = sa; pwd = 121212");
SqlDataAdapter sda = new SqlDataAdapter("select * from 表1",conn);
DataSet ds = new DataSet();
sda.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
和
private void button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server = USER-20150322KM;database = huanghe;uid = sa; pwd = 121212");
SqlCommand cmd = new SqlCommand("select * from 表1",conn);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
有什么区别?两个输出的结果是一样的啊。还有 sda.Fill(ds);这行, sda.Fill(ds);和 sda.Fill(ds,"表1");结果也是一样的啊。晕了。求大神指教
{
SqlConnection conn = new SqlConnection("server = USER-20150322KM;database = huanghe;uid = sa; pwd = 121212");
SqlDataAdapter sda = new SqlDataAdapter("select * from 表1",conn);
DataSet ds = new DataSet();
sda.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
和
private void button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server = USER-20150322KM;database = huanghe;uid = sa; pwd = 121212");
SqlCommand cmd = new SqlCommand("select * from 表1",conn);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
}
有什么区别?两个输出的结果是一样的啊。还有 sda.Fill(ds);这行, sda.Fill(ds);和 sda.Fill(ds,"表1");结果也是一样的啊。晕了。求大神指教