hi,
if i select one item in combobox,click ok button then that items GUID is saved in table,i want save the GUID of which item i selected in the Combobox.i dont want save the selected item.plz give the code,plz help me,plz
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
roy himanshuPosted Sep 5, 2009, 1:29 AM
its working but column name is saved but valuenot saved.plz help me.my codeing is paste below
private void Itemmaster_Load(object sender, EventArgs e)
{
cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["con"]);
da1 = new SqlDataAdapter("select *from ITEMMASTER", cn);
da2 = new SqlDataAdapter("select *from ITEMCATAGARY", cn);
ds = new DataSet();
da1.Fill(ds, "ITEMMASTER");
da2.Fill(ds, "ITEMCATAGARY");
cmd = new SqlCommand();
comboBox1.DataSource = ds.Tables["ITEMCATAGARY"];
comboBox1.DisplayMember = "Itemname";
comboBox1.ValueMember = "guid";
comboBox1.EndUpdate();
}
private void Add_btn_Click(object sender, EventArgs e)
{
try
{
DataRow dr = ds.Tables["ITEMMASTER"].NewRow();
dr[1] = textBox1.Text;
dr[2] = textBox2.Text;
dr[3] = textBox3.Text;
dr[4] = comboBox1.ValueMember.ToString();
dr[5] = textBox5.Text;
dr[6] = textBox6.Text;
dr[7] = dateTimePicker1.Text;
dr[8] = textBox8.Text;
dr[9] = textBox9.Text;
dr[10] = textBox10.Text;
dr[11] = textBox11.Text;
dr[12] = textBox12.Text;
dr[13] = textBox13.Text;
dr[14] = textBox14.Text;
ds.Tables["ITEMMASTER"].Rows.Add(dr);
cb = new SqlCommandBuilder(da1);
da1.Update(ds, "ITEMMASTER");
MessageBox.Show("Data Saved Successfully");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
foreach (Control item in Controls)
{
if (item is TextBox)
{
item.Text = "";
}
}
}
PLZ HELP ME
Roei BarPosted Sep 4, 2009, 2:45 AM
select id,value from tbl
the ID is the guid and the value is the display
than on the combo bind it to the sql return datatable
this.cbPositions.DataSource =dt;
this.cbPositions.DisplayMember = "Name";
this.cbPositions.ValueMember="ID";
and on selected take cbPositions.selectedValue