如何将文本文件保存到数据库(SQL Server 2005)? [英] How to save an text file into a database (sql server 2005)?

查看:88
本文介绍了如何将文本文件保存到数据库(SQL Server 2005)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将文本文件保存到sql server 2005数据库中????
有可能吗?也有可能找回它吗?
因为是初学者..pls可以帮助我...

I Want to save an text file into a sql server 2005 database???
is it possible???and also possible for retriving it??
since am an beginner..pls help me...

推荐答案

如果您在代码中执行此操作,请尝试:
If you are doing this in code then try:
byte[] bytes = File.ReadAllBytes(@"D:\Temp\myTextFile.txt");
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (myColumn1) VALUES (@C1)", con))
        {
        com.Parameters.AddWithValue("@C1", bytes);
        com.ExecuteNonQuery();
        }
    }


如果您通过T-SQL进行操作,请尝试以下链接,

http://www.simple-talk.com/sql/t-sql-programming/reading-and-writing-files-in-sql-server-using-t-sql/ [ http://sqlserver2000. database.aspfaq.com/how-do-i-load-text-or-csv-file-data-into-sql-server.html [ http://blog.sqlauthority.com/2008/02/06/sql-server-import-csv-file-into-sql-server-using-bulk-insert-load-comma -delimited-file-into-sql-server/ [
If you are doing it through T-SQL try these links,

http://www.simple-talk.com/sql/t-sql-programming/reading-and-writing-files-in-sql-server-using-t-sql/[^]

http://sqlserver2000.databases.aspfaq.com/how-do-i-load-text-or-csv-file-data-into-sql-server.html[^]

http://blog.sqlauthority.com/2008/02/06/sql-server-import-csv-file-into-sql-server-using-bulk-insert-load-comma-delimited-file-into-sql-server/[^]

Hope it helps.


这篇关于如何将文本文件保存到数据库(SQL Server 2005)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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