Exception with DataAdapter.Update ! [modified]
-
Hi, I have an xml file with employee data and need to uplaod its content to the database. For this I have used dataset.ReadXml method and then I am using the dataadapter.update method to upload the content of the dataset to the database. Here is the code: protected void Button1_Click(object sender, EventArgs e) { string path = @"D\emp.xml"; string dsTable = ""; string connectionString = @"Server = DB\SQL2; Database = CWBDB; user = sa; password = sa"; DataSet ds = new DataSet("EMPDS"); ds.ReadXml(path); foreach (DataTable t in ds.Tables) { dsTable = t.ToString(); } SqlConnection con = new SqlConnection(connectionString); SqlDataAdapter da = new SqlDataAdapter(); da.TableMappings.Add("EMP", dsTable); if ((da.Update(ds))>0) { Label1.Text = "Uploaded the data successfully"; } else { Label1.Text = "Could not Upload the data"; } } But I see an exception: "Update unable to find TableMapping['Table'] or DataTable 'Table'." Please help! -- modified at 8:15 Wednesday 11th April, 2007
Rakesh
-
Hi, I have an xml file with employee data and need to uplaod its content to the database. For this I have used dataset.ReadXml method and then I am using the dataadapter.update method to upload the content of the dataset to the database. Here is the code: protected void Button1_Click(object sender, EventArgs e) { string path = @"D\emp.xml"; string dsTable = ""; string connectionString = @"Server = DB\SQL2; Database = CWBDB; user = sa; password = sa"; DataSet ds = new DataSet("EMPDS"); ds.ReadXml(path); foreach (DataTable t in ds.Tables) { dsTable = t.ToString(); } SqlConnection con = new SqlConnection(connectionString); SqlDataAdapter da = new SqlDataAdapter(); da.TableMappings.Add("EMP", dsTable); if ((da.Update(ds))>0) { Label1.Text = "Uploaded the data successfully"; } else { Label1.Text = "Could not Upload the data"; } } But I see an exception: "Update unable to find TableMapping['Table'] or DataTable 'Table'." Please help! -- modified at 8:15 Wednesday 11th April, 2007
Rakesh
rockyl wrote:
foreach (DataTable t in ds.Tables) { dsTable = t.ToString(); }
What are you trying do here ? i think it will overwrite in each loop
Thanks and Regards Sandeep If you want something you never had, do something you have never done!
-
rockyl wrote:
foreach (DataTable t in ds.Tables) { dsTable = t.ToString(); }
What are you trying do here ? i think it will overwrite in each loop
Thanks and Regards Sandeep If you want something you never had, do something you have never done!
da.TableMappings.Add("EMP", dsTable); The above statement of my code makes a mapping between database table and dataset table, the first parameter is the database table name and the 2nd paramaeter is dataset table name. So I am getting the table name from the dataset and passing to it so that a mapping may occur between the database table and the dataset table. In short I will explain what I am trying to do. Theres an xml file consisting of Employee data, I need to upload this xml content to the Database. For this I have used the Dataset.fill(xmlpath) and then using the dataadapter for updating the data to the database. Now u can see my previous code and get clear understanding.
Rakesh