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]);
精彩评论