为什么用datagirdview显示不了。
privatevoidFrmBookRevise_Load(objectsender,EventArgse){DataTablemydt=newDataTable();S...
private void FrmBookRevise_Load(object sender, EventArgs e)
{
DataTable mydt = new DataTable();
SqlConnection conn = Sqlclient.Client();
conn.Open();
string cmd = "select bId as 图书编号,bName as 图书名称,bNumber as 数量,bSore as 类别 from Bmanage";
SqlDataAdapter adpter = new SqlDataAdapter(cmd, conn);
DataSet myds = new DataSet();
adpter.Fill(myds);
mydt = myds.Tables[0];
BindingSource bds = new BindingSource();
dataGridView1.DataSource = bds;
bds.DataSource = mydt;
} 展开
{
DataTable mydt = new DataTable();
SqlConnection conn = Sqlclient.Client();
conn.Open();
string cmd = "select bId as 图书编号,bName as 图书名称,bNumber as 数量,bSore as 类别 from Bmanage";
SqlDataAdapter adpter = new SqlDataAdapter(cmd, conn);
DataSet myds = new DataSet();
adpter.Fill(myds);
mydt = myds.Tables[0];
BindingSource bds = new BindingSource();
dataGridView1.DataSource = bds;
bds.DataSource = mydt;
} 展开
2个回答
展开全部
SqlDataReader sdr = cmd.ExecuteReader();
dataGridView1.DataSource = sdr;
这里改成下面的试试
sqldataadapter da=new sqldataadapter(sql,Dac.conn);
datatable dt=new datatable();
da.fill(dt);
dataGridView1.DataSource =dt;
dataGridView1.DataSource = sdr;
这里改成下面的试试
sqldataadapter da=new sqldataadapter(sql,Dac.conn);
datatable dt=new datatable();
da.fill(dt);
dataGridView1.DataSource =dt;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询