I think I have a weird doubt!!
I have created a table using C#[with a tool not programatically ] in mdb file, then I am inserting the values to that table, what the issue is I don't know how many columns are available in that table, but I wanna insert value from the datagridview..
Spire.DataExport.Access.AccessExport accessExport = new Spire.DataExport.Access.AccessExport();
accessExport.DataSource = Spire.DataExport.Common.ExportSource.DataTable;
accessExport.DataTable = this.dataGridView2.DataSource as System.Data.DataTable;
accessExport.DatabaseName = saveFileDialog1.FileName;
accessExport.TableName = "ExtractedTable";
accessExport.SaveToFile();
//OleDbCommand cmdt = new OleDbCommand("Create Table "+profiletablegrid. ", con);
string strDirectory = saveFileDialog1.FileName;
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strDirectory);
conn.Open();
for (int i = 41; i < dataGridView2.Rows.Count; i++)
{
for (int j = 0; j < dataGridView2.Rows[i].Cells.Count; j++)
{
OleDbCommand cmdd = new OleDbCommand("Insert into sample values(@a,@b,@c,@d)", conn);
cmdd.Parameters.Add("@a", OleDbType.VarChar).Value = dataGridView2.Rows[i].Cells[j].Value.ToString();
cmdd.Parameters.Add("@b", OleDbType.VarChar).Value = dataGridView2.Rows[i].Cells[j].Value.ToString();
cmdd.Parameters.Add("@c", OleDbType.VarChar).Value = dataGridView2.Rows[i].Cells[j].Value.ToString();
cmdd.Parameters.Add("@d", OleDbType.VarChar).Value = dataGridView2.Rows[i].Cells[j].Value.ToString();
cmdd.ExecuteNonQuery();
}
}
So Since I know the columns I am inserting 4 values, but if I don't know how many columns are there, then how can i insert the value... I can count the datagridview total columns, but how can I insert according to that?