0
我有一个包含请购单编号的组合框。现在,当我在组合框中选择一个请求项目(如r001)时,其信息应填充到下面的数据网格中。我已经使用了这个过程。但我不知道如何将datagrid视图控件绑定到信息。在选择组合框中的项目时从数据库填充datagridview
代码:
private void cmbreqno_SelectedIndexChanged(object sender, EventArgs e)
{
cmd.Connection = con;
if (con.State != ConnectionState.Open)
{
con.Open();
}
txtcc.Text = "";
int selection = Convert.ToInt16(((KeyValuePair<string, string>)(cmbreqno.SelectedItem)).Key);
if (selection.ToString() != "")
{
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "itemname";
cmd.Parameters.AddWithValue("@req_no", selection);
dsitemname.Clear();
adp = new SqlDataAdapter(cmd);
adp.Fill(dsitemname);
txtcc.Text = dsitemname.Tables[1].Rows[0]["costcenter_no"].ToString();
txtcc.Tag = dsitemname.Tables[1].Rows[0]["costcenter_id"].ToString();
cmd.Parameters.Clear();
}
存储过程:
alter proc itemname
(
@req_no int
)
as begin
select item_name,brand_name,quantity,requisitionitem.item_cost
from requisitionitem left outer join item
on requisitionitem.item_id=item.item_id
where [email protected]_no
end
谢谢。你也可以告诉我,如果我想添加更多列到这些列我应该怎么做? – Kaushik27 2013-05-13 09:05:23
你必须创建自己的列(如果你想从数据源中填充它们,'DataPropertyName'设置为从db对应的列名称),并设置'dataGridView1.AutoGenerateColumns = false; – gzaxx 2013-05-13 09:09:44