hi
i'm using oledb to read from an excel file into dataset.
my program is showing the dataset using datagridview,
when i'm trying to change the cell content and update the dataset i get an error :
"Update unalbe to find tablemapping or DataTable
my code is:
public static string conString = "provider=Microsoft.Jet.OLEDB.4.0;data source=..\\..\\Data.xls;" +
"Extended Properties=\"Excel 8.0;HDR=NO;IMEX=1;\"";
string[,] AllData = new string[27,27];
static OleDbConnection con = new OleDbConnection(conString);
DataSet dataset1;
OleDbDataAdapter dadapter;
DataGrid myDatagrid;
private void button1_Click(object sender, EventArgs e)
{
try
{
con.Open();
dadapter = new OleDbDataAdapter("select * from [Vertexes$]", con);
dataset1 = new DataSet();
dadapter.Fill(dataset1, "Vertexes");
DataTable Table = dataset1.Tables["Vertexes"];
int a =0 ,b = 0;
foreach (DataRow row in Table.Rows)
{
foreach (DataColumn col in Table.Columns)
{
AllData[a, b] = row[col].ToString();
b++;
if (b == 27)
{
b = 0; a++;
if (a == 27)
break;
}
}
if (a == 27)
break;
}
con.Close();
myDatagrid = new DataGrid();
myDatagrid.DataSource = dataset1.Tables["Vertexes"];
myDatagrid.CaptionText = "All Data";
myDatagrid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
myDatagrid.Location = new System.Drawing.Point(256, 56);
myDatagrid.Name = "dataGrid1";
myDatagrid.Size = new System.Drawing.Size(488, 200);
myDatagrid.TabIndex = 6;
myDatagrid.Visible = false;
myDatagrid.BorderStyle = BorderStyle.Fixed3D;
myDatagrid.CaptionBackColor = Color.Blue;
this.Controls.Add(myDatagrid);
}
catch (Exception ex)
{
MessageBox.Show("Error in retrieving data: " + ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
myDatagrid.Visible = true;
}
private void button3_Click(object sender, EventArgs e)
{
try
{
DataSet changes = dataset1.GetChanges();
if (changes != null)
{
con.Open();
dadapter.Update(changes);
con.Close();
dataset1.AcceptChanges();
}
}
catch (Exception ex)
{
MessageBox.Show("ErrorR: " + ex.Message);
dataset1.RejectChanges();
con.Close();
}
}