W
wgraulich
Guest
I have created a combobox named Dispatcher and linked it to a sql database. One of the names in the sql database that is linked to the combobox named Dispatcher is "D'Ambrosio, James S". When I select that name from the combobox dropdown list and hit the save button I get the error " System.DataSql.Client.SqlException: 'Incorrect syntax near 'Ambrosio'.
Below is my code for the save button. How can I make it so that I can use the name as it appears in the combobox dropdown?
private void Savebtn_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("Insert into Overnight_Parking(Callers_Name,Address,Start_Date,End_Date,Callers_Phone,City,Reason,Description,Dispatcher) values ('" + Callers_Name.Text + "','" + Address.Text + "','" + Start_Date.Value.ToString("yyyy-MM-dd") + "', '" + End_Date.Value.ToString("yyyy-MM-dd") + "','" + Callers_Phone.Text + "','" + City.Text +"','" + Reason.Text + "','" + Description.Text + "','" + Dispatcher.Text + "')",con);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Data Saved Successfully");
//textbox clear code
Callers_Name.Text = "";
Callers_Phone.Text = "";
City.Text = "";
Address.Text = "";
Reason.Text = "";
Description.Text = "";
}
Continue reading...
Below is my code for the save button. How can I make it so that I can use the name as it appears in the combobox dropdown?
private void Savebtn_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("Insert into Overnight_Parking(Callers_Name,Address,Start_Date,End_Date,Callers_Phone,City,Reason,Description,Dispatcher) values ('" + Callers_Name.Text + "','" + Address.Text + "','" + Start_Date.Value.ToString("yyyy-MM-dd") + "', '" + End_Date.Value.ToString("yyyy-MM-dd") + "','" + Callers_Phone.Text + "','" + City.Text +"','" + Reason.Text + "','" + Description.Text + "','" + Dispatcher.Text + "')",con);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Data Saved Successfully");
//textbox clear code
Callers_Name.Text = "";
Callers_Phone.Text = "";
City.Text = "";
Address.Text = "";
Reason.Text = "";
Description.Text = "";
}
Continue reading...