求C#实现文本TXT文件导入SQL 公司要写个软件,给我安排排了一部分就是在VS2005下C#实现文本TXT文件导入SQL,很少接触编程,大家帮帮忙,谢谢了,越详细越好,最好带注释 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 private void SaveFile() { Form1 frm = new Form1(); FileStream filestream = new FileStream(Application.StartupPath + "\\a.txt", FileMode.Open, FileAccess.Read); BinaryReader filerd = new BinaryReader(filestream, Encoding.Default); byte[] filebyte = new byte[filestream.Length]; filerd.Read(filebyte, 0, (int)filestream.Length); frm.OpenConn(); OleDbCommand comm = new OleDbCommand("insert into file (id,file) Values(@fid,@file) ", frm.dbconn); comm.Parameters.AddWithValue("@fid", "0001"); comm.Parameters.AddWithValue("@file", DBNull.Value); comm.Parameters["@file"].Value = filebyte; comm.ExecuteNonQuery(); } private void ReadFile() { Form1 frm = new Form1(); frm.OpenConn(); OleDbCommand comm = new OleDbCommand("select * from file", frm.dbconn); OleDbDataAdapter da = new OleDbDataAdapter(comm); DataSet ds = new DataSet(); da.Fill(ds); byte[] filebyte = (byte[])ds.Tables[0].Rows[0]["File"]; // System.Text.Encoding mycode = new System.Text.Encoding(); this.richTextBox1.AppendText(Encoding.Default.GetString(filebyte)); } 不需要c#,sql本来就支持文本导入用bcp命令就可以了EXEC master..xp_cmdshell 'bcp "dbname..tablename" in c:\DT.txt -c -Sservername -Usa -Ppassword' 列子是Access,转Sql,您应该没问题把?将File字段设置为color=#FF0000]image,[[/color],应为image可以存储超过8000字节;Form1 frm = new Form1();frm.OpenConn();frm.dbconn是因为我在Form1中已经定义了连接数据库,换成您自己的连接; 多线程lock问题 C#怎样获取文件相对路径 ArrayList 的用法 API画弧 用C#写代码,却发现实现某功能需要#include几个比较大的头文件。请问怎么解决这个问题啊。 listview的问题 ConfigurationSettings 怎样在命令提示符下运行C#文件? 如何获得文本框中选定的字符串 系统背景界面 输入一个数字,让它以后面一个数等于前面两个数相加? 如何过滤datagridview的零值
private void SaveFile()
{
Form1 frm = new Form1();
FileStream filestream = new FileStream(Application.StartupPath + "\\a.txt", FileMode.Open, FileAccess.Read);
BinaryReader filerd = new BinaryReader(filestream, Encoding.Default);
byte[] filebyte = new byte[filestream.Length];
filerd.Read(filebyte, 0, (int)filestream.Length); frm.OpenConn(); OleDbCommand comm = new OleDbCommand("insert into file (id,file) Values(@fid,@file) ", frm.dbconn);
comm.Parameters.AddWithValue("@fid", "0001");
comm.Parameters.AddWithValue("@file", DBNull.Value);
comm.Parameters["@file"].Value = filebyte;
comm.ExecuteNonQuery(); }
private void ReadFile()
{
Form1 frm = new Form1();
frm.OpenConn();
OleDbCommand comm = new OleDbCommand("select * from file", frm.dbconn);
OleDbDataAdapter da = new OleDbDataAdapter(comm);
DataSet ds = new DataSet();
da.Fill(ds);
byte[] filebyte = (byte[])ds.Tables[0].Rows[0]["File"];
// System.Text.Encoding mycode = new System.Text.Encoding();
this.richTextBox1.AppendText(Encoding.Default.GetString(filebyte));
}
EXEC master..xp_cmdshell 'bcp "dbname..tablename" in c:\DT.txt -c -Sservername -Usa -Ppassword'
将File字段设置为color=#FF0000]image,[[/color],应为image可以存储超过8000字节;
Form1 frm = new Form1();
frm.OpenConn();
frm.dbconn
是因为我在Form1中已经定义了连接数据库,换成您自己的连接;