保存附件代码没有报错,但导出的文件里面只有System.Byte[]内容
我的导入与导出的代码均没有报错,导入的代码如下:
openfiledialog = new OpenFileDialog();
openfiledialog.ShowDialog();//打开对话框
string fileroute = openfiledialog.FileName;//路径
string filename = openfiledialog.SafeFileName;
if (filename.Length < 1)//如果没有选中文件就退出
{
MessageBox.Show("未选中文件");
return;
}
FileStream fs = new FileStream(fileroute, FileMode.Open);//文件流
int len = (int)fs.Length;//流长度
byte[] fileData = new byte[len];
fs.Read(fileData, 0,len);
fs.Close();
openfileinsert(socodetext, filename, fileData, "");//保存附件函数
filenametextbox.Text = filename;
MessageBox.Show("插入附件成功");
导出的代码如下
string socode = bsocode.Text.Trim();
string filename = filenametextbox.Text;//文件名
savefiledialog = new SaveFileDialog();
savefiledialog.FileName = filename;
savefiledialog.ShowDialog();
string fileroute = savefiledialog.FileName;//文件路径
//读出附件,用sqldatareader
SqlConnection sqlcn = new SqlConnection(command.);
string filesql = "select * from Dsalefile where socode = '" + socode +"'";
SqlCommand cmd = new SqlCommand(filesql, sqlcn);
SqlDataReader sdr;
sqlcn.Open();
sdr = cmd.ExecuteReader();
sdr.Read();//开始读
//或byte[] imageData = (byte[])dr[2];
System.Data.SqlTypes.SqlBinary sb = sdr.GetSqlBinary(3);//第4列是有附件的列
FileStream fs = new FileStream(fileroute, FileMode.Create);
fs.Write(sb.Value, 0, sb.Value.Length);
fs.Close();//写入流的关闭
sdr.Close();
sqlcn.Close();
运行的时候都 没有报错,只是导出的文件里面只有"System.Byte[]"内容,到底代码错在那里了呢,请高人帮忙.