12 个解决方案
#1
小弟我在线等.谢谢.有例子也可以加有QQ94039634!谢谢.解决了100分肯定送上!
#2
System.IO.FileStream fs = new System.IO.FileStream("",System.IO.FileMode.Open);
byte[] bytes = new byte[fs.Length];
fs.Read(bytes,0,fs.Length);
fs.Close();
System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection("连接字符串");
System.Data.SqlClient.SqlCommand cm = new System.Data.SqlClient.SqlCommand();
cm.Connection = cnn;
cm.CommandText = "insert into table1 (myfile) value (@myfile)";
cm.Parameters.Add("@myfile",System.Data.SqlDbType.Image);
cm.Parameters["@myfile"].Value = bytes;
cnn.Open();
cm.ExecuteNonQuery();
cnn.Close();
byte[] bytes = new byte[fs.Length];
fs.Read(bytes,0,fs.Length);
fs.Close();
System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection("连接字符串");
System.Data.SqlClient.SqlCommand cm = new System.Data.SqlClient.SqlCommand();
cm.Connection = cnn;
cm.CommandText = "insert into table1 (myfile) value (@myfile)";
cm.Parameters.Add("@myfile",System.Data.SqlDbType.Image);
cm.Parameters["@myfile"].Value = bytes;
cnn.Open();
cm.ExecuteNonQuery();
cnn.Close();
#3
楼上正解
#4
Eddie005(♂) 暴赱 『零零伍』(︶︵︶)
不好意思,我忘了说是VB.NET里面.
对不起!
不好意思,我忘了说是VB.NET里面.
对不起!
#5
dim fs System.IO.FileStream= new System.IO.FileStream("",System.IO.FileMode.Open)
dim bytes() as byte = new byte(fs.Length)
fs.Read(bytes,0,fs.Length)
fs.Close()
dim cnn as System.Data.SqlClient.SqlConnection = new System.Data.SqlClient.SqlConnection("连接字符串")
dim cm = new System.Data.SqlClient.SqlCommand()
cm.Connection = cnn
cm.CommandText = "insert into table1 (myfile) value (@myfile)"
cm.Parameters.Add("@myfile",System.Data.SqlDbType.Image)
cm.Parameters("@myfile").Value = bytes
cnn.Open()
cm.ExecuteNonQuery()
cnn.Close()
dim bytes() as byte = new byte(fs.Length)
fs.Read(bytes,0,fs.Length)
fs.Close()
dim cnn as System.Data.SqlClient.SqlConnection = new System.Data.SqlClient.SqlConnection("连接字符串")
dim cm = new System.Data.SqlClient.SqlCommand()
cm.Connection = cnn
cm.CommandText = "insert into table1 (myfile) value (@myfile)"
cm.Parameters.Add("@myfile",System.Data.SqlDbType.Image)
cm.Parameters("@myfile").Value = bytes
cnn.Open()
cm.ExecuteNonQuery()
cnn.Close()
#6
谢谢,我去测试下.可以的话.马上回来给分!
太感谢了!!!
太感谢了!!!
#7
取:
dim cnn as System.Data.SqlClient.SqlConnection = new System.Data.SqlClient.SqlConnection("连接字符串")
dim cm as System.Data.SqlClient.SqlCommand = new System.Data.SqlClient.SqlCommand()
cm.Connection = cnn
cm.CommandText = "select myfile from table1 where id=1"
cnn.Open()
dim dr as System.Data.SqlClient.SqlDataReader =cm.ExecuteReader()
dim bytes() as byte = dr(0)
cnn.Close()
dim cnn as System.Data.SqlClient.SqlConnection = new System.Data.SqlClient.SqlConnection("连接字符串")
dim cm as System.Data.SqlClient.SqlCommand = new System.Data.SqlClient.SqlCommand()
cm.Connection = cnn
cm.CommandText = "select myfile from table1 where id=1"
cnn.Open()
dim dr as System.Data.SqlClient.SqlDataReader =cm.ExecuteReader()
dim bytes() as byte = dr(0)
cnn.Close()
#8
这是读出放到一个路径下:
string filePath=this.saveFileDialog1.FileName;
SqlConnection myConnection=new SqlConnection();
SqlCommand myCommand=new SqlCommand();
myConnection.ConnectionString=ConnectionString;
myConnection.Open();
string sql="select 字段名 from 表名where ID="+id;
myCommand.Connection=myConnection;
myCommand.CommandType=CommandType.Text;
myCommand.CommandText=sql;
SqlDataReader myDataReader=myCommand.ExecuteReader();
if(myDataReader.Read())
{
System.IO.FileInfo myFileInfo=new FileInfo(filePath);
System.IO.FileStream myFileStream=myFileInfo.Open(System.IO.FileMode.OpenOrCreate);
byte[] imgData=(byte[])myDataReader["FileContent"];
foreach(byte a in imgData)
{
myFileStream.WriteByte(a);
}
myFileStream.Close();
myDataReader.Close();
}
myConnection.Close();
MessageBox.Show("文件保存成功!",this.Text,MessageBoxButtons.OK,MessageBoxIcon.Information);
filePath是路径+文件名。
string filePath=this.saveFileDialog1.FileName;
SqlConnection myConnection=new SqlConnection();
SqlCommand myCommand=new SqlCommand();
myConnection.ConnectionString=ConnectionString;
myConnection.Open();
string sql="select 字段名 from 表名where ID="+id;
myCommand.Connection=myConnection;
myCommand.CommandType=CommandType.Text;
myCommand.CommandText=sql;
SqlDataReader myDataReader=myCommand.ExecuteReader();
if(myDataReader.Read())
{
System.IO.FileInfo myFileInfo=new FileInfo(filePath);
System.IO.FileStream myFileStream=myFileInfo.Open(System.IO.FileMode.OpenOrCreate);
byte[] imgData=(byte[])myDataReader["FileContent"];
foreach(byte a in imgData)
{
myFileStream.WriteByte(a);
}
myFileStream.Close();
myDataReader.Close();
}
myConnection.Close();
MessageBox.Show("文件保存成功!",this.Text,MessageBoxButtons.OK,MessageBoxIcon.Information);
filePath是路径+文件名。
#9
mark
#10
这时候,你得到的是二进制数组而已,下面的使用就有很多种情况了,
如果是提供下载,你可以直接用HttpResponse导出文件;
如果需要读取里面的内容,那么就先把它保存在服务器的一个临时文件夹里,那么一般读取excel文件内容的方式也有几种,规则的文件直接使用ado.net把它当作access数据库读取也可以,调用Excel类库读取也可以...
如果是提供下载,你可以直接用HttpResponse导出文件;
如果需要读取里面的内容,那么就先把它保存在服务器的一个临时文件夹里,那么一般读取excel文件内容的方式也有几种,规则的文件直接使用ado.net把它当作access数据库读取也可以,调用Excel类库读取也可以...
#11
不好意思,好象不怎么好用吗?
先送上点分数,有没有详细点的例子.
先送上点分数,有没有详细点的例子.
#12
mark
#1
小弟我在线等.谢谢.有例子也可以加有QQ94039634!谢谢.解决了100分肯定送上!
#2
System.IO.FileStream fs = new System.IO.FileStream("",System.IO.FileMode.Open);
byte[] bytes = new byte[fs.Length];
fs.Read(bytes,0,fs.Length);
fs.Close();
System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection("连接字符串");
System.Data.SqlClient.SqlCommand cm = new System.Data.SqlClient.SqlCommand();
cm.Connection = cnn;
cm.CommandText = "insert into table1 (myfile) value (@myfile)";
cm.Parameters.Add("@myfile",System.Data.SqlDbType.Image);
cm.Parameters["@myfile"].Value = bytes;
cnn.Open();
cm.ExecuteNonQuery();
cnn.Close();
byte[] bytes = new byte[fs.Length];
fs.Read(bytes,0,fs.Length);
fs.Close();
System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection("连接字符串");
System.Data.SqlClient.SqlCommand cm = new System.Data.SqlClient.SqlCommand();
cm.Connection = cnn;
cm.CommandText = "insert into table1 (myfile) value (@myfile)";
cm.Parameters.Add("@myfile",System.Data.SqlDbType.Image);
cm.Parameters["@myfile"].Value = bytes;
cnn.Open();
cm.ExecuteNonQuery();
cnn.Close();
#3
楼上正解
#4
Eddie005(♂) 暴赱 『零零伍』(︶︵︶)
不好意思,我忘了说是VB.NET里面.
对不起!
不好意思,我忘了说是VB.NET里面.
对不起!
#5
dim fs System.IO.FileStream= new System.IO.FileStream("",System.IO.FileMode.Open)
dim bytes() as byte = new byte(fs.Length)
fs.Read(bytes,0,fs.Length)
fs.Close()
dim cnn as System.Data.SqlClient.SqlConnection = new System.Data.SqlClient.SqlConnection("连接字符串")
dim cm = new System.Data.SqlClient.SqlCommand()
cm.Connection = cnn
cm.CommandText = "insert into table1 (myfile) value (@myfile)"
cm.Parameters.Add("@myfile",System.Data.SqlDbType.Image)
cm.Parameters("@myfile").Value = bytes
cnn.Open()
cm.ExecuteNonQuery()
cnn.Close()
dim bytes() as byte = new byte(fs.Length)
fs.Read(bytes,0,fs.Length)
fs.Close()
dim cnn as System.Data.SqlClient.SqlConnection = new System.Data.SqlClient.SqlConnection("连接字符串")
dim cm = new System.Data.SqlClient.SqlCommand()
cm.Connection = cnn
cm.CommandText = "insert into table1 (myfile) value (@myfile)"
cm.Parameters.Add("@myfile",System.Data.SqlDbType.Image)
cm.Parameters("@myfile").Value = bytes
cnn.Open()
cm.ExecuteNonQuery()
cnn.Close()
#6
谢谢,我去测试下.可以的话.马上回来给分!
太感谢了!!!
太感谢了!!!
#7
取:
dim cnn as System.Data.SqlClient.SqlConnection = new System.Data.SqlClient.SqlConnection("连接字符串")
dim cm as System.Data.SqlClient.SqlCommand = new System.Data.SqlClient.SqlCommand()
cm.Connection = cnn
cm.CommandText = "select myfile from table1 where id=1"
cnn.Open()
dim dr as System.Data.SqlClient.SqlDataReader =cm.ExecuteReader()
dim bytes() as byte = dr(0)
cnn.Close()
dim cnn as System.Data.SqlClient.SqlConnection = new System.Data.SqlClient.SqlConnection("连接字符串")
dim cm as System.Data.SqlClient.SqlCommand = new System.Data.SqlClient.SqlCommand()
cm.Connection = cnn
cm.CommandText = "select myfile from table1 where id=1"
cnn.Open()
dim dr as System.Data.SqlClient.SqlDataReader =cm.ExecuteReader()
dim bytes() as byte = dr(0)
cnn.Close()
#8
这是读出放到一个路径下:
string filePath=this.saveFileDialog1.FileName;
SqlConnection myConnection=new SqlConnection();
SqlCommand myCommand=new SqlCommand();
myConnection.ConnectionString=ConnectionString;
myConnection.Open();
string sql="select 字段名 from 表名where ID="+id;
myCommand.Connection=myConnection;
myCommand.CommandType=CommandType.Text;
myCommand.CommandText=sql;
SqlDataReader myDataReader=myCommand.ExecuteReader();
if(myDataReader.Read())
{
System.IO.FileInfo myFileInfo=new FileInfo(filePath);
System.IO.FileStream myFileStream=myFileInfo.Open(System.IO.FileMode.OpenOrCreate);
byte[] imgData=(byte[])myDataReader["FileContent"];
foreach(byte a in imgData)
{
myFileStream.WriteByte(a);
}
myFileStream.Close();
myDataReader.Close();
}
myConnection.Close();
MessageBox.Show("文件保存成功!",this.Text,MessageBoxButtons.OK,MessageBoxIcon.Information);
filePath是路径+文件名。
string filePath=this.saveFileDialog1.FileName;
SqlConnection myConnection=new SqlConnection();
SqlCommand myCommand=new SqlCommand();
myConnection.ConnectionString=ConnectionString;
myConnection.Open();
string sql="select 字段名 from 表名where ID="+id;
myCommand.Connection=myConnection;
myCommand.CommandType=CommandType.Text;
myCommand.CommandText=sql;
SqlDataReader myDataReader=myCommand.ExecuteReader();
if(myDataReader.Read())
{
System.IO.FileInfo myFileInfo=new FileInfo(filePath);
System.IO.FileStream myFileStream=myFileInfo.Open(System.IO.FileMode.OpenOrCreate);
byte[] imgData=(byte[])myDataReader["FileContent"];
foreach(byte a in imgData)
{
myFileStream.WriteByte(a);
}
myFileStream.Close();
myDataReader.Close();
}
myConnection.Close();
MessageBox.Show("文件保存成功!",this.Text,MessageBoxButtons.OK,MessageBoxIcon.Information);
filePath是路径+文件名。
#9
mark
#10
这时候,你得到的是二进制数组而已,下面的使用就有很多种情况了,
如果是提供下载,你可以直接用HttpResponse导出文件;
如果需要读取里面的内容,那么就先把它保存在服务器的一个临时文件夹里,那么一般读取excel文件内容的方式也有几种,规则的文件直接使用ado.net把它当作access数据库读取也可以,调用Excel类库读取也可以...
如果是提供下载,你可以直接用HttpResponse导出文件;
如果需要读取里面的内容,那么就先把它保存在服务器的一个临时文件夹里,那么一般读取excel文件内容的方式也有几种,规则的文件直接使用ado.net把它当作access数据库读取也可以,调用Excel类库读取也可以...
#11
不好意思,好象不怎么好用吗?
先送上点分数,有没有详细点的例子.
先送上点分数,有没有详细点的例子.
#12
mark