Insert Data from datagrid view to database table from datagrid view

Posted by Vulcan under C# on 7/10/2018 | Points: 10 | Views : 432 | Status : [Member] | Replies : 1
I am trying to save some data into an SQLite database, but I am having a problem actually saving the data to the database , the error i am facing is that my data cannot be saved into my database

Here is my current code: I do really need help in this because I really have no idea where it goes wrong

SQLiteConnection con = new
SQLiteConnection("DataSource=|DataDirectory|\\trendchart.db");
con.Open();
for (int i = 0; i < dataGridView1.Rows.Count ; i++)
{
try
{
SQLiteCommand g = new SQLiteCommand("INSERT INTO data(TOP(1), TOP(2) VALUES ('" + dataGridView1.Rows[i].Cells[0].Value.ToString() + "" +
dataGridView1.Rows[i].Cells[1].Value.ToString() + "" +
dataGridView1.Rows[i].Cells[2].Value.ToString() + "" +
dataGridView1.Rows[i].Cells[3].Value.ToString() + "')", con);

g.ExecuteNonQuery();
MessageBox.Show("DataSaved please check if its correct ");
}
catch
{
MessageBox.Show("Error 404");
}
}




Responses

Posted by: Musuvo on: 9/14/2018 [Member] Starter | Points: 25

Up
0
Down
if you format a sd card what happens
https://www.bitwar.net/course/card/272.html


Vulcan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response