想把查询的结果添加datagridview里去,不知道要如何写,查询的语句如下:
string Goods_str = "SELECT Goods_ID, Goods_Name, Goods_Param, (SELECT Goods_Ctg_Name FROM tb_goods_ctg WHERE tb_goods_ctg.Goods_Ctg_ID = tb_goods.Goods_Ctg_ID) as Ctg, (SELECT UOM_Name FROM tb_uom WHERE tb_uom.UOM_ID = tb_goods.UOM_ID) as UOM, Goods_Barcode FROM tb_goods WHERE Goods_Barcode = '";
Goods_str += this.txtEnterCode.Text.Trim() + "'";
SqlDataReader Goods_DR = DBSetup.GetDR(Goods_str);
Goods_DR.Read();
if (Goods_DR.HasRows)
{
//this.label1.Text = Goods_DR["Goods_Barcode"].ToString();
//this.label2.Text = Goods_DR["Goods_Name"].ToString();
//this.label3.Text = Goods_DR["Goods_Param"].ToString();
//this.label4.Text = Goods_DR["Ctg"].ToString();
//this.label5.Text = Goods_DR["UOM"].ToString();
}
else
{
MessageBox.Show("无此商品","提示",MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Goods_DR.Close();
string Goods_str = "SELECT Goods_ID, Goods_Name, Goods_Param, (SELECT Goods_Ctg_Name FROM tb_goods_ctg WHERE tb_goods_ctg.Goods_Ctg_ID = tb_goods.Goods_Ctg_ID) as Ctg, (SELECT UOM_Name FROM tb_uom WHERE tb_uom.UOM_ID = tb_goods.UOM_ID) as UOM, Goods_Barcode FROM tb_goods WHERE Goods_Barcode = '";
Goods_str += this.txtEnterCode.Text.Trim() + "'";
SqlDataReader Goods_DR = DBSetup.GetDR(Goods_str);
Goods_DR.Read();
if (Goods_DR.HasRows)
{
//this.label1.Text = Goods_DR["Goods_Barcode"].ToString();
//this.label2.Text = Goods_DR["Goods_Name"].ToString();
//this.label3.Text = Goods_DR["Goods_Param"].ToString();
//this.label4.Text = Goods_DR["Ctg"].ToString();
//this.label5.Text = Goods_DR["UOM"].ToString();
}
else
{
MessageBox.Show("无此商品","提示",MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Goods_DR.Close();
解决方案 »
- XML转DataSet格式问题
- 【新手提问】c# winform 能否实现窗体左右分屏显示,左边调用记事本程序,右边调用其他的系统程序
- 解压文件的时候是否可以中毒?
- 100分求一个超级见天问题
- Crystalreport怎么在最后一页的页码后面加字
- Access 数据库导入到SQL 中关于科学计数法的问题
- 求教大学:如何将google earth嵌入c#开发的窗体中
- 访问远程access数据库.怎么编程绕过在登陆远程计算机弹出的对话框?
- 高分求救!!!关于Remoting,如何调用两个远程对象
- 撤消一个焦点,帮忙。
- 高手请进,如何重画控件使其显示不规则样式。
- OleDbType 标准表达式中数据类型不匹配
然后两句就直接邦定
datagridview.datasoure=dataset.table[0];
datagridview.databind();
rows.add属性也可以加
datagridview.datasoure=Goods_DR;
datagridview.databind();
Goods_DR.Close();
之后根据循环把Goods_DR的值,都加进去。
之后,再用dgw的绑定。一定可以行的。要下班了。88
foreach (DataRow row in table.Rows)
{
DataGridViewRow grow = dataGridView1.Rows[dataGridView1.Rows.Add()];
grow.Cells[0].Value = row[0];
grow.Cells[1].Value = row[1];
grow.Cells[2].Value = row[2];
grow.Cells[3].Value = row[3];
}
//查询方法
private void SearchMethod()
{
string sql = "select * from roomtype";
conn = DBHelper.conn();
da = new SqlDataAdapter(sql, conn);
ds = new DataSet();
da.Fill(ds);
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = ds.Tables[0];
}只要指定dataGridView的数据源就可以了
//查询方法
private void SearchMethod()
{
string sql = "select * from roomtype";
conn = DBHelper.conn();
da = new SqlDataAdapter(sql, conn);
ds = new DataSet();
da.Fill(ds);
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = ds.Tables[0];
}只要指定dataGridView的数据源就可以了
private void SearchMethod()
{
string sql = "select * from roomtype";
conn = DBHelper.conn();
da = new SqlDataAdapter(sql, conn);
ds = new DataSet();
da.Fill(ds);
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = ds.Tables[0];
}
如果担心sql语句有问题,在分析器里运行的试试然后再写。
你是说Goods_str?这是可以的,我还把它查询的结果赋值给几个lab来显示,没有出现问题。
先将当前绑定清空this.dataGrid1.DataSource = null;
然后在重新绑定this.dataGrid.DataSource = ds.Tables[0];
Goods_str += this.txtEnterCode.Text.Trim() + "'";
SqlDataReader Goods_DR = DBSetup.GetDR(Goods_str);
Goods_DR.Read();
if (Goods_DR.HasRows)
{
//this.label1.Text = Goods_DR["Goods_Barcode"].ToString();
//this.label2.Text = Goods_DR["Goods_Name"].ToString();
//this.label3.Text = Goods_DR["Goods_Param"].ToString();
//this.label4.Text = Goods_DR["Ctg"].ToString();
//this.label5.Text = Goods_DR["UOM"].ToString();
DataTable dt=new DataTable();
dt.Load(Goods_DR);
DataGridView1.Datasource=dt;
}
else
{
MessageBox.Show("无此商品","提示",MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Goods_DR.Close();
那样的话你就需要获取数据的时候把数据添加到 已经绑定的表中.
比如说原来已经有个数据源 date1 这次你得到的数据添加到原来的date1中对应的表中.
那样的话你就需要获取数据的时候把数据添加到 已经绑定的表中.
比如说原来已经有个数据源 date1 这次你得到的数据添加到原来的date1中对应的表中.
那样的话你就需要获取数据的时候把数据添加到 已经绑定的表中.
比如说原来已经有个数据源 date1 这次你得到的数据添加到原来的date1中对应的表中.
int currentcellrow = this.dgvPOLine.CurrentCell.RowIndex;
string TheGoodsName = GoodsInfo_DR["Goods_Name"].ToString();
string TheGoodsParam = GoodsInfo_DR["Goods_Param"].ToString();
this.dgvPOLine[1, currentcellrow].Value = TheGoodsName;
this.dgvPOLine[2, currentcellrow].Value = TheGoodsParam;