Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML to access database via Dataset

Status
Not open for further replies.

SQL2KDBA69

Programmer
Feb 4, 2004
227
0
0
US
im trying to import a xml file into my database. this is my code

Code:
if (ofdServers.ShowDialog() == DialogResult.OK)
            {
                OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Remote\\Serverlist.mdb");
                conn.Open();
                OleDbDataAdapter da = new OleDbDataAdapter("Select * from Servers",conn);
                DataRow dr;
                DataSet ds = new DataSet();
                da.Fill(ds);
                ds.Clear();
                ds.ReadXml(ofdServers.FileName);
                int dsrowcount = ds.Tables[0].Rows.Count;
                try
                {
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        for (int i = 0; i < dsrowcount; i++)
                        {
                            dr = ds.Tables[0].NewRow();
                            dr["ipaddress"] = ds.Tables[0].Rows[i]["ipaddress"].ToString();
                            dr["admin_port"] = ds.Tables[0].Rows[i]["admin_port"].ToString();
                            dr["n4admin_password"] = ds.Tables[0].Rows[i]["n4admin_password"].ToString();
                            dr["Web_Console"] = ds.Tables[0].Rows[i]["web_console"].ToString();
                            ds.Tables[0].Rows.Add(dr);
                        }

                        da.Update(ds, "Servers");
                        LoadTree();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Import Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
                }
                finally
                {
                    conn.Close();
                    conn.Dispose();
                }
            }

here is error i get :

{System.InvalidOperationException: Update unable to find TableMapping['Servers'] or DataTable 'Servers'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top