如何在c#中将数据从文本文件写入数据库

问题描述:

我有一个文本文件,其中有一个名称文件,我想阅读它,然后我想将它写入数据库。

我该怎么做?

请帮帮我



Nirav Prabtani

删除了喊叫。

I have a text file which name file and I want to read it and then I want to wrıte it to data base.
how can I do this ?
please help me

:Nirav Prabtani
Removed Shouting.

尝试:
string text = File.ReadAllText(path);
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (myColumn1) VALUES (@COL1)", con))
        {
        com.Parameters.AddWithValue("@COL1", text);
        com.ExecuteNonQuery();
        }
    }


plz查看链接



使用C#进行简单的ADO.NET数据库读取,插入,更新和删除。 [ ^ ]

http://social.msdn.microsoft.com/Forums/en-US/6d91eac6-d990-4d64-9861-625e05c715bb/c -connect-database-and-createwrite-into-textfile?forum = csharplanguage [ ^ ]
plz check the link

Simple ADO.NET Database Read, Insert, Update and Delete using C#.[^]
http://social.msdn.microsoft.com/Forums/en-US/6d91eac6-d990-4d64-9861-625e05c715bb/c-connect-database-and-createwrite-into-textfile?forum=csharplanguage[^]