将.csv文件上传到数据库 [英] upload .csv files to Database

查看:110
本文介绍了将.csv文件上传到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想在我的网页中上传.csv格式的文件,当我单击更新"按钮时,它将自动创建带有列的表
在这里
文件名=表名和
文件的第一行(标题)=表的列

如何在MS SQL Server中为其编写代码. .

i want upload only .csv format files in my web page and as soon as i click on Update button it will automatically create table with columns
here
file name= table name and
first row of the file (headings)= columns of the table

how to write the code for it in MS SQL server. .

推荐答案

首先,您需要了解如何执行SQL代码.

下面介绍如何从c#执行SQL语句.

http://msdn.microsoft.com/zh-CN/library/0k7hxwz6 (v = vs.80).aspx [快速CSV阅读器 [ http://www.w3schools.com/sql/sql_create_table.asp [ http://www.w3schools.com/sql/sql_insert.asp [
First you need to know how to execute SQL code.

The following describes that how to execute SQL statements from c#.

http://msdn.microsoft.com/en-US/library/0k7hxwz6(v=vs.80).aspx[^]

Then you need to read in the CSV to get the structure of the file. One such reader is available on CodeProject :-)

A Fast CSV Reader[^]

Next you need to construct an SQL statement which creates the table. The following explains the CREATE TABLE command is SQL.

http://www.w3schools.com/sql/sql_create_table.asp[^]

Then you need to execute this command against SQL.

Then you need to read the data in with your CSV reader and insert into the new table.

The following is information on the INSERT command.

http://www.w3schools.com/sql/sql_insert.asp[^]


这篇关于将.csv文件上传到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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