我将如何从XML文件读取数据&将数据插入SQL服务器。 [英] How I will do data read from XML file & insert the data into SQL server .

查看:87
本文介绍了我将如何从XML文件读取数据&将数据插入SQL服务器。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#控制台应用程序。在应用程序运行后,数据将存储到XML文件中。我将如何将相同的数据插入SQL db表。我想将相同的数据插入数据库。从xml节点读取&插入列。



我尝试过:



服务器

home rajesh1 / home

serverlist 182.117.197.350 / serverlist

主机rajesh主机

网站DOWN / site

i have a C# console application .where after application run data will store into XML file . how i will insert the same data into SQL db table. i want to insert same data into database . read from xml nodes & insert into columns .

What I have tried:

Server
home rajesh1 /home
serverlist 182.117.197.350 /serverlist
host rajesh host
site DOWN /site

推荐答案

你需要做的是将你的问题分解成更小的部分然后你不会感到如此不知所措,以至于你不知道从哪里开始。



1)你需要做的第一件事就是弄清楚如何用c#读取XML。



在c中读取XML文件 - Google搜索 [ ^ ]



如果序列化是一个选项,请查看C#中的工作方式



Google [ ^ ]



2)如果你没有使用序列化,那么你需要读取XML并将其映射到某种对象(或者你可以写在这里插入查询)。



我的意思是你可以有一个说话的对象......人。下面是将XML元素映射到Person属性的步骤,并将每个Person添加到Person类型的列表中。



3)遍历您的列表Person(例如:var persons = new< Person>();)并编写插入查询,或使用EntityFramework将数据插入数据库。



实体框架C# - Google搜索 [ ^ ]



一旦开始在这个项目中,如果您遇到困难,请随时回过头来清楚解释您的问题和任何相关的代码示例。我们不是为您完成项目的服务。您还需要记住,我们无法访问您的计算机,您的硬盘驱动器,也不会读取您的想法或了解您的项目。模糊的问题除了让人们感到恼火,他们无法为你提供足够的帮助。如果您能够提供清晰的解释和相关的代码示例,我相信有人会很乐意在您需要时为您提供帮助。
What you need to do is break your problem down into smaller pieces and then you won't feel so overwhelmed that you don't know where to start.

1) First thing you need to do is figure out how to read XML in c#.

read XML file in c - Google Search[^]

If serialization is an option, review how that works in C#

Google[^]

2) If you did not use serialization, then you need to read the XML and map it to an object of some sort (or you could just write insert queries here).

By this i mean you could have an object of say...Person. Here would be the step that you map the XML elements to the properties of Person and add each Person to a list of type Person.

3) Loop through your list of Person (ex: var persons = new <Person>();) and write insert queries, or use EntityFramework to insert that data into your database.

Entity framework C# - Google Search[^]

Once you get started on this project, should you get stuck, feel free to come back with a clear explanation of your issue and any relevant code samples. We are not a service that does your projects for you. You also need to remember we don't have access to your computer, your hard drive, nor do we read minds or know anything about your project. Vague questions do nothing but get people annoyed that they can't provide you adequate assistance. If you are able to provide a clear explanation and relevant code samples I am sure someone will be happy to help you when you need it.


您也可以借助此链接进行导入从XML文件到SQL Server的数据

将数据从XML文件导入和处理到SQL Server表中 [ ^ ]
you can also take the help of this link to importing data from XML file to SQL Server
Importing and Processing data from XML files into SQL Server tables[^]


这篇关于我将如何从XML文件读取数据&amp;将数据插入SQL服务器。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆