求助,关于导出保存数据库中的图片! 如题,在数据库中以二进制方式保存照片,但现在就是想批量导出所需要的图片并自动保存成文件,用程序如何实现这样的功能,请高手指教! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 改改连接字符串,改改sql语句,传入你要保存的路径就好了private void GetAndWriteData(string path) { try { Byte[] blob = null; FileStream fs = null; // string strCnn = "server=(local);Initial Catalog=Master;UID=pl;PWD="; string strCnn = this.ConnectString; // string strSql = "select Data from UserControls where id = '"+this.FileID+"'"; string strSql = "select "+this.DataFieldName+" from "+this.TableName+" where "+this.IDFieldName+" = '"+this.FileID+"'"; SqlConnection Cnn = new SqlConnection(strCnn); SqlCommand Cmd = new SqlCommand(strSql,Cnn); Cnn.Open(); SqlDataReader sReader = Cmd.ExecuteReader(); sReader.Read(); blob = new Byte[(sReader.GetBytes(0, 0, null, 0, int.MaxValue))]; sReader.GetBytes(0, 0, blob, 0, blob.Length); sReader.Close(); Cnn.Close(); fs = new FileStream(path, FileMode.Create, FileAccess.Write); fs.Write(blob, 0, blob.Length); fs.Close(); } catch(SqlException ex) { MessageBox.Show("Sql Exception: " + ex.Message); } catch(Exception ex) { MessageBox.Show("Exception: " + ex.Message); } } 向数组中插入200万个随机不重复的数字 通过ADO.NET向数据库添加多行数据时报错 想请教如何按特定字符读取txt文件 为什么csdn的下载区的东西下载不了 头疼啊,头疼! 在虚拟主机上创建目录失败,请高手指点 关于SQL中插入新记录后,如何获取最新的ID ASP.NET视频在线播放 有关上位机和下位机的无线通信 winform里面如何实现grid数据变化的识别 请教高手, .NET中有没有提供调节系统音量的控件啊? 视频聊天软件,发源代码,找志同道合的人
private void GetAndWriteData(string path)
{
try
{
Byte[] blob = null;
FileStream fs = null;
// string strCnn = "server=(local);Initial Catalog=Master;UID=pl;PWD=";
string strCnn = this.ConnectString;
// string strSql = "select Data from UserControls where id = '"+this.FileID+"'";
string strSql = "select "+this.DataFieldName+" from "+this.TableName+" where "+this.IDFieldName+" = '"+this.FileID+"'";
SqlConnection Cnn = new SqlConnection(strCnn);
SqlCommand Cmd = new SqlCommand(strSql,Cnn);
Cnn.Open();
SqlDataReader sReader = Cmd.ExecuteReader();
sReader.Read();
blob = new Byte[(sReader.GetBytes(0, 0, null, 0, int.MaxValue))];
sReader.GetBytes(0, 0, blob, 0, blob.Length);
sReader.Close();
Cnn.Close();
fs = new FileStream(path, FileMode.Create, FileAccess.Write); fs.Write(blob, 0, blob.Length);
fs.Close();
}
catch(SqlException ex)
{
MessageBox.Show("Sql Exception: " + ex.Message);
}
catch(Exception ex)
{
MessageBox.Show("Exception: " + ex.Message);
}
}