xmlFile = XmlReader.Create("Product.xml", new XmlReaderSettings()); ds.ReadXml(xmlFile); int i = 0; connection.Open(); for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) { product_ID = Convert.ToInt32(ds.Tables[0].Rows[i].ItemArray[0]); Product_Name = ds.Tables[0].Rows[i].ItemArray[1].ToString(); product_Price = Convert.ToDouble(ds.Tables[0].Rows[i].ItemArray[2]); sql = "insert into Product values(" + product_ID + ",'" + Product_Name + "'," + product_Price + ")"; command = new SqlCommand(sql, connection); adpter.InsertCommand = command; adpter.InsertCommand.ExecuteNonQuery(); } connection.Close(); MessageBox.Show("Done .. "); } } }
Liked By
Write Answer
Insert data from XML to database in C#
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy
Join MindStick Community
You have need login or register for voting of answers or question.
Sumit Kesarwani
15-Jun-2013