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; } } } } 
throw new SqlException();. And in thecatchblock, change the exception type toSqlException. - Rootwareпвапвакт овапия. 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