我有一个带有申请号的组合框。现在,当我在组合框中选择 1 个申请项目(如 r001)时,其信息应填充到下面的数据网格中。我为此使用了一个 stroed 程序。但我不知道如何将数据网格视图控件绑定到信息。
代码:
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 requisitionitem.req_no=@req_no
end