开发者

importing xml data from a file on my system to a sql db created in microsoft visual studio 2010

开发者 https://www.devze.com 2023-03-23 03:40 出处:网络
I have created a customer database in Microsoft Visual Studio with one table called customer details. On my system I have an xml file which I created with data that I would like to import into the par

I have created a customer database in Microsoft Visual Studio with one table called customer details. On my system I have an xml file which I created with data that I would like to import into the particular table in the database. However I am havi开发者_开发知识库ng trouble do so since there is no import feature in Microsoft Visual Studio like there is in Access. Can anyone please help?


This is the code I tried that worked below. Will use the link since code seems to be more efficient.

DataSet reportData = new DataSet();
reportData.ReadXml(Server.MapPath("newdata.xml"));


SqlConnection connection = new SqlConnection(
   @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Customer.mdf;
   Integrated Security=True;User Instance=True"
);

SqlBulkCopy sbc = new SqlBulkCopy(connection);
sbc.DestinationTableName = "CustomerDetails";

connection.Open();
sbc.WriteToServer(reportData.Tables[0]);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号