how to save the datagridview items into the database using csharp
Note it is windows application.
In datagridview design screen as follows;
Name Mobile_No Message
A 9789503250 xxx
B 9840578905 yyy
C 9950412484 zzz
D 9790567890 aaa
E 9978904580 bbb
When i click the save button, the above datagridview records should be saved into the database.
Save Button code as follows;
private void Btn_Save_Click(object sender, EventArgs e)
when i click the save button error shows as follows;
{
try
{
for (int i = 0; i < DGV_Fac_SMS.RowCount; i++)
{
sql = "insert into Tb_Faculty_Schedule_Timetable [Name],[Mobile No],[Message]";
sql = sql + " values ( '" + (DGV_Fac_SMS.Rows[i].Cells[0].Value.ToString()) + "','" + (DGV_Fac_SMS.Rows[i].Cells[1].Value.ToString()) + "','" + (DGV_Fac_SMS.Rows[i].Cells[2].Value.ToString()) + "')";
GFun.Error = " ";
GFun.InsertAccessData(sql);
if (GFun.Error.ToString() != "")
{
MessageBox.Show(GFun.Error.ToString(), "Error");
//this.Cursor = Cursors.Arrow;
return;
}
GFun.OleDbCon.Close();
MessageBox.Show("Record Inserted Successfully", "Records Inserted", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
MessageBox.Show("Error", ex.ToString());
return;
}
}
syntax error in insert into statement.
what is my problem, in my insert code.
please help me.
brunda kPosted Mar 18, 2013, 8:31 PM
Gonzalo LeonPosted Mar 18, 2013, 2:59 PM
INSERT INTO