| | |
error when trying to update dataset with oledb
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Nov 2007
Posts: 146
Reputation:
Solved Threads: 0
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['Table'] or DataTable ['Table']
my code is:
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['Table'] or DataTable ['Table']
my code is:
c# Syntax (Toggle Plain Text)
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(); } }
•
•
Join Date: Nov 2007
Posts: 146
Reputation:
Solved Threads: 0
i found the answer. i needed to write:
now does anyone knows how can i apply the changes from the dataset to the excel file ?
c# Syntax (Toggle Plain Text)
dadapter.TableMappings.Add("Table","Table");
now does anyone knows how can i apply the changes from the dataset to the excel file ?
![]() |
Similar Threads
- data adapter update method won't work (VB.NET)
- How can I update my access database via VB.net using this code (VB.NET)
- Need Help With Program (VB.NET)
- How to Update a Data Table? (ASP.NET)
- Updating Combo Box (Visual Basic 4 / 5 / 6)
- An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system. (VB.NET)
- Updating a record in an MS Access database file using DataSets (VB.NET)
- Please Help Me, I Am to Be Fired! (ASP.NET)
- Error connecting to database (ASP.NET)
Other Threads in the C# Forum
- Previous Thread: A transport-level error has occurred when receiving results from the server. (provide
- Next Thread: Date Picking from windows form Calender
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array bitmap box broadcast buttons c# chat check checkbox class client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms ftp function gdi+ httpwebrequest image index install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation visualstudio webbrowser windows winforms wpf xml





