往数据库中插入图片的代码

q23tr34t 2004-10-19 09:05:44
我要住SQL sever 数据库中的 list 表中的 456 字段中插入一张图片,下面的代码是我拷过来的,有些地方我也不懂是什么意思,运行起来出错了.请高手帮我改改


System.Data.SqlClient.SqlConnection connect =new System.Data.SqlClient.SqlConnection();
string con = System.Configuration.ConfigurationSettings.AppSettings.Get(0);
System.Data.SqlClient.SqlCommand command=new System.Data.SqlClient.SqlCommand("insert into list values ('1a','1b',@i)",connect);

private void Button1_Click(object sender, System.EventArgs e)
{
this.connect.ConnectionString=this.con;
this.connect.Open();
byte[] ib=new Byte[60000];
FileStream fs=new FileStream(@"E:\hhr.jpg",FileMode.Open ,FileAccess.Read );
fs.Read(ib,0,60000);
this.command.Parameters.Add("@i",SqlDbType.Image,(int)fs.Length);
this.command.Parameters["@i"].Value=ip;
this.command.ExecuteNonQuery();
this.connect.Close();
}

错误信息是
1,找不到类型或命名空间 FileStream
2,找不到类型或命名空间 fs
3,ip 在类或命名空间 WebApplication4.WebForm5中不存在
...全文
82 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
q23tr34t 2004-10-19
  • 打赏
  • 举报
回复
我的SQL sever 数据库中的 list 表中有三个字段,分别是 '123' '234' '456' 我想往 '456' 字段中插入一个图片.运行下面的代码,每次按下 button 按钮后, 打开 list 表,就只看见 '123' '456' 字段中插入了 1a 1b 而'456'字段中没有看到插入了图片啊.请问程序哪里错了?



System.Data.SqlClient.SqlConnection connect =new System.Data.SqlClient.SqlConnection();
string con = System.Configuration.ConfigurationSettings.AppSettings.Get(0);
private void Button1_Click(object sender, System.EventArgs e)
{
System.Data.SqlClient.SqlCommand command=new System.Data.SqlClient.SqlCommand("insert into list values ('1a','1b',@i)",connect);
this.connect.ConnectionString=this.con;
this.connect.Open();
byte[] aaa=new Byte[60000];
FileStream fs=new FileStream(@"E:\hhr.jpg",FileMode.Open ,FileAccess.Read );
fs.Read(aaa,0,60000);
command.Parameters.Add("@i",SqlDbType.Image,(int)fs.Length);
command.Parameters["@i"].Value=aaa;
command.ExecuteNonQuery();
this.connect.Close();


}
xiaohutushen 2004-10-19
  • 打赏
  • 举报
回复
1.using System.IO;
3.ip ===>换成"aaa";

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧