Hi guys,
I am trying to export the datagridview1 to another table in my database. I see a bunch of SQL but not for OLE. Can someone help me with the syntax. I am basically trying to create a check out form, so when the user checks out. Will take all the columns and rows and export into another table that I have.
I tried both of the following to export into another table called Authors_Table.
Thanks
[/FONT][/COLOR]
I am trying to export the datagridview1 to another table in my database. I see a bunch of SQL but not for OLE. Can someone help me with the syntax. I am basically trying to create a check out form, so when the user checks out. Will take all the columns and rows and export into another table that I have.
I tried both of the following to export into another table called Authors_Table.
Thanks
C#:
[COLOR=#000000][FONT=Calibri] private void button1_Click(object sender, EventArgs e)
{
OleDbConnection connect = new OleDbConnection(); //Creates the connection
connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=H:\VB Projects\binding\binding\books.accdb;Persist Security Info=False";
connect.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connect;
command.CommandText = "SELECT * FROM Authors";
OleDbDataAdapter da = new OleDbDataAdapter();
DataSet ds = new DataSet();
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Authors_table";
da.Fill(ds, "Authors_table");
connect.Close();
}
[/FONT][/COLOR]
[COLOR=#000000][FONT=Calibri]
[/FONT][/COLOR]
[COLOR=#000000][FONT=Calibri]I also tried another code and get a different error: Additional information: The SelectCommand property has not been initialized before calling 'Fill'.[/FONT][/COLOR]
[COLOR=#000000][FONT=Calibri]
[/FONT][/COLOR]
[COLOR=#000000][FONT=Calibri] private void button1_Click(object sender, EventArgs e)
{
[/FONT][/COLOR]
[COLOR=#000000][FONT=Calibri] OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=H:\VB Projects\binding\binding\books.accdb;Persist Security Info=False");
OleDbDataAdapter ad = new OleDbDataAdapter();
DataSet ds = new DataSet();
OleDbCommand cmd = new OleDbCommand();
con.Open();
ad.SelectCommand = new OleDbCommand("SELECT * FROM Authors");
// ad.InsertCommand = new OleDbCommand("INSERT INTO * FROM Authors", con);
ad.Fill(ds, "Authors_table");
ad.SelectCommand.ExecuteNonQuery();
con.Close();
[/FONT][/COLOR]
[COLOR=#000000][FONT=Calibri] }
[/FONT][/COLOR]