I need to insert a cobobox value ,date value into database but am not sure if this is the method...i keep getting an exception saying 'Incorrect syntax near '@Numberpassengers'.'
private void button1_Click(object sender, EventArgs e)
{
string c = "";
string s = "";
string d = "";
string t = "";
if (CarNameCombo.SelectedIndex >= 0 && SourceCombo.SelectedIndex>=0 && DestinationCombo.SelectedIndex>=0&&comboBox7.SelectedIndex>=0)
c = CarNameCombo.Items[CarNameCombo.SelectedIndex].ToString();
s = SourceCombo.Items[SourceCombo.SelectedIndex].ToString();
d = SourceCombo.Items[DestinationCombo.SelectedIndex].ToString();
t = comboBox7.Items[comboBox7.SelectedIndex].ToString();
string date=dateTimePicker1.Text;
string date1=dateTimePicker2.Text;
SqlConnection conn = new SqlConnection("Data Source=PRAVEEN\\SQLEXPRESS;Initial Catalog=travelbooking;Integrated Security=True");
SqlCommand cmd = new SqlCommand("insert into BookDetails(CarName,Source,Destination,Date,FromAddress,ToAddress,Time,Numberpassengers)VALUES(@CarName,@Source,@Destination,@Date,@FromAddress,@ToAddress,@Time,@Numberpassengers");
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
cmd.Parameters.AddWithValue("@CarName", c);
cmd.Parameters.AddWithValue("@Source", s);
cmd.Parameters.AddWithValue("@Destination",d);
cmd.Parameters.AddWithValue("@Date",date);
cmd.Parameters.AddWithValue("@FromAddress", richTextBox1.Text);
cmd.Parameters.AddWithValue("@ToAddress", richTextBox2.Text);
cmd.Parameters.AddWithValue("@Time", date1);
cmd.Parameters.AddWithValue("@Numberpassengers",t);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();