Guys I am trying to save ONE row of a DataGridView to a database.
Till now I have got examples where we need to SPECIFY the column names and numbers in z INSERT statemnt. as below.
string col1 = datagridview1[0, datagridview1s.CurrentCell.RowIndex].Value.ToString();
string col2 = datagridview1[1, datagridview1.CurrentCell.RowIndex].Value.ToString();
string col3 = datagridview1[2, datagridview1.CurrentCell.RowIndex].Value.ToString();
string insert_sql = "INSERT INTO YourTable(col1,col2,col3)VALUES('"+ col1 +"','"+ col2 +"','"+ col3 +"'");
this.getcom(insert_sql);
}
catch(Exception ex)
{ Message.Box(ex);}
}
Is there any way to do the INSERT without having to hardcode the column details ? I want to save the row in the database using the column headers of the datagridview as the column name in database.