PDA

View Full Version : ارسال آیتم از کمبو باکس به پایگاه داده



maryam.g
شنبه 21 دی 1387, 23:12 عصر
سلام
من می خواستم مقداری را که کاربر در یک combobox انتخاب می کند را بوسیله پارامتر به پایگاه داده SQL ارسال کنم .چطور این کار رو انجام بدم


SqlConnection labconection = newSqlConnection(Properties.Settings.Default.LABOR ATORYConnectionString);
SqlCommand labcommand = newSqlCommand("Insert INTO Reciption (P_ID,P_name,P_family,D_ID,insurance,P_tel,address )" +
"values(@P_ID,@P_name,@P_family,@D_ID,@insurance,@P _tel,@address)", labconection);
labcommand.Parameters.AddWithValue("@P_ID", textBox1.Text);
labcommand.Parameters.AddWithValue("@P_name", textBox2.Text);
labcommand.Parameters.AddWithValue("@P_family", textBox3.Text);
labcommand.Parameters.AddWithValue("@D_ID", textBox4.Text);
labcommand.Parameters.AddWithValue("@insurance", ????????????????);
labcommand.Parameters.AddWithValue("@P_tel", textBox6.Text);
labcommand.Parameters.AddWithValue("@address", textBox5.Text);
try

{
labconection.Open();
labcommand.ExecuteNonQuery();
MessageBox.Show("اطلاعات ثبت شد", "پیام ثبت ",
MessageBoxButtons.OK,
MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1);
}
catch (SqlException SqlExceptionError)
{
MessageBox.Show(SqlExceptionError.Message);
}
finally

{
if (labconection.State != ConnectionState.Closed)
labconection.Close();
}


حالا به جای علامت سوال ها می خوام مقدار انتخاب شده در کمبو باکس رو بفرستم ..چی باید بنویسم:متفکر:
ممنون از لطفتون :لبخند:

mehdi_9009
یک شنبه 22 دی 1387, 05:12 صبح
combobox.text

danial82
یک شنبه 22 دی 1387, 09:45 صبح
combobox.selecteditem.tostring()