本文介绍了如何在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();
        }
    }



这篇关于如何在c#中将数据从文本文件写入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 15:07
查看更多