connectionString = @"Data Source=HP\SQLEXPRESS;database=MK;Integrated Security=true"; connection = new SqlConnection(connectionString); foreach (int rowIndex in lstNewRows) { string insrtQry = "insert into " + comboBox1.Text + " values("; foreach (DataGridViewCell cell in dataGridView1.Rows[rowIndex].Cells) { insrtQry += "'" + cell.Value.ToString() + "',"; } insrtQry = insrtQry.TrimEnd(",".ToCharArray()); insrtQry += ")"; try { connection.Open(); adapter.InsertCommand = new SqlCommand(insrtQry, connection); adapter.InsertCommand.ExecuteNonQuery(); MessageBox.Show("Row inserted !! "); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } private void insert_Click(object sender, EventArgs e) { InsertInfo(); } private void dataGridView1_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e) { lstNewRows.Add(e.Row.Index); }
Transaction
Rollback
parameterized queries
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)