У меня проблема со вставкой данных в SQL Server.
Я пытаюсь добавить данные, используя C #, в свою базу данных SQL Server с этим кодом:
private void button1_Click(object sender, EventArgs e)
{
con = new SqlConnection("Data Source=DEMO;Initial Catalog=Shipping;Integrated Security=True");
con.Open();
cmd = new SqlCommand(
@"INSERT INTO SailorForm
( firstName,
lastName,
nationallity,
age,
gender,
address,
deckRank,
engineRank,
electricalRank,
contractdate,
contractType,
shipname,
durationoftour,
country/port,
healthissues,
durationoftour2,
shiptype,
Certificateslicenses,
WorkExperience,
idnumber
)
VALUES
( @firstName,
@lastName,
@nationallity,
@age,
@gender,
@address,
@deckRank,
@engineRank,
@electricalRank,
@contractdate,
@contractType,
@shipname,
@durationoftour,
@country/port,
@healthissues,
@durationoftour2,
@shiptype,
@Certificateslicenses,
@WorkExperience,
@idnumber )", con);
cmd.Parameters.Add("@firstname", textBox1.Text);
cmd.Parameters.Add("@lastname", textBox2.Text);
cmd.Parameters.Add("@nationallity", textBox3.Text);
cmd.Parameters.AddWithValue("@age", textBox5.Text);
cmd.Parameters.Add("@gender", radioButton1.Text);
cmd.Parameters.Add("@address", textBox4.Text);
cmd.Parameters.Add("@deckrank", comboBox1.SelectedItem.ToString());
cmd.Parameters.Add("@enginerank", comboBox2.SelectedItem.ToString());
cmd.Parameters.Add("@electricalRank", comboBox3.SelectedItem.ToString());
cmd.Parameters.Add("@contractdate", dateTimePicker1.MaxDate);
cmd.Parameters.Add("@contractType", radioButton3.Text);
cmd.Parameters.Add("@shipname", textBox6.Text);
cmd.Parameters.Add("@durationoftour", dateTimePicker2.MaxDate);
cmd.Parameters.Add("@country/port", textBox11.Text);
cmd.Parameters.Add("@healthissues", textBox13);
cmd.Parameters.Add("@durationoftour2", dateTimePicker3.MaxDate);
cmd.Parameters.Add("@shiptype", comboBox4.SelectedItem.ToString());
cmd.Parameters.Add("@Certificateslicenses", textBox14.Text);
cmd.Parameters.Add("@WorkExperience", textBox15);
cmd.Parameters.Add("@idnumber", textBox7.Text);
cmd.ExecuteNonQuery();
}