The data is manually filled in dataGridView1. By pressing button184_Click, the request should be executed (writing data from dataGridView1) and the whole thing should go into the database file .mdf. In place of this ... problem ... How can it be localized? 1 table 7 columns

ps please check ... I have everything right here?

private void button184_Click(object sender, EventArgs e) { var ConnStr = "Connection"; try { using (SqlConnection conn = new SqlConnection(ConnStr)) { using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; conn.Open(); for (int i = 0; i<dataGridView1.Rows.Count; i++) { var strQuery = "INSERT INTO Поезд (№_вываывфаыв,твыип_пввыаа,паывт_отвыавыаения,пуыавывакт_прыыва,ство_ввыпвов,коапия,певапь_кввапя)" + "VALUES (@№ ппвапа,@тпвапп повапа,@пват оапапвапия,@папт прапия,@копватво ввапнов,@ковапния,@певапиаость вапвания)"; comm.CommandText = strQuery; comm.Parameters.AddWithValue("@№ пвапда", dataGridView1.Rows[i].Cells[0].Value); comm.Parameters.AddWithValue("@тпвап папа", dataGridView1.Rows[i].Cells[1].Value); comm.Parameters.AddWithValue("@пвапвакт овапия", dataGridView1.Rows[i].Cells[2].Value); comm.Parameters.AddWithValue("@пвапт праптия", dataGridView1.Rows[i].Cells[3].Value); comm.Parameters.AddWithValue("@квапво ввапнов", dataGridView1.Rows[i].Cells[4].Value); comm.Parameters.AddWithValue("@коапя", dataGridView1.Rows[i].Cells[5].Value); comm.Parameters.AddWithValue("@переапть капапия", dataGridView1.Rows[i].Cells[6].Value); // больше параметров ... comm.ExecuteNonQuery(); } conn.Close(); } } } catch (Exception ex) { Console.WriteLine(ex); throw; } } } } 

enter image description here

  • one
    Haha, oh, this hand-made obfuscation =) Sorry, I could not resist. - Arthur Edgarov
  • Try throw new SqlException(); . And in the catch block, change the exception type to SqlException . - Rootware
  • 3
    It would be better if you created the stored procedures in the database beforehand, and then simply called them by passing the necessary parameters from the code, rather than cramming these horrible пвапвакт овапия . Before pushing any SQL query into C # code, the work of this query needs to be tested on the base using SQL Server Management Studio, then a stored procedure is created on its basis and being fully confident that it is working, insert the call into the code. - Bulson
  • At least showed you the fields in the table, but how can you check if the data types do not match? For example, sql expects an int, and you string it up with it - Alexsandr Ter
  • @Alexsandr Ter thanks I corrected found errors - user298940

0