通过c#代码在informix数据库中保存图像? [英] Saving image in informix database by c# code ?

查看:60
本文介绍了通过c#代码在informix数据库中保存图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过c#代码在informix数据库中保存图像?



无法使用c#代码在informix数据库中保存图像。





所有步骤仅在查询即将执行时才起作用抛出错误E42000:( - 201)发生了语法错误。



以下是代码。



mycon.Open();

int len =上传。 PostedFile.ContentLength;

byte [] pic = new byte [len];

HttpPostedFile img = Upload.PostedFile;

Response.Write( 文件大小=+ pic);

img.InputStream.Read(pic,0,len);

//Upload.PostedFile.InputStream.Read(pic ,0,len);

string str =插入imageinfo(名称,地址,照片)值(''+ txtname.Text +'',''+ txtaddress.Text + '',+ pic +); //,照片,@照片

mycmd = ne w OleDbCommand(str,mycon);

// mycmd.Parameters.AddWithValue(@ id,int.Parse(txtid.Text));

mycmd.Parameters .AddWithValue(@ name,txtname.Text);

mycmd.Parameters.AddWithValue(@ address,txtaddress.Text);

mycmd.Parameters.AddWithValue (@photo,pic);

mycmd.ExecuteNonQuery();

mycon.Close();

lblMessage.Text =图像详细信息已成功插入;

Response.Redirect(〜/ RetriveImage.aspx);

mycon.Close();

解决方案

阅读以下内容:

http://stackoverflow.com/questions/6267159/sql-informix-how-do-i-add-a-blob-when- do-an-insert-using-the-net-cs [ ^ ]



http://stackoverflow.com/questions/6319858/informix-c-how-do-i-properly-set-unset-a-blob-field [ ^ ]



http://stackoverflow.com/questions/3603203/appending-to-informix-blob-without-running-out-of-memory [ ^ ]

Saving image in informix database by c# code ?

Unable to save image in informix database by using c# code.


All the steps work only when the query is about to get executed it throws error "E42000: (-201) A syntax error has occurred."

Below is the code.

mycon.Open();
int len = Upload.PostedFile.ContentLength;
byte[] pic = new byte[len];
HttpPostedFile img = Upload.PostedFile;
Response.Write("Size of file = " + pic);
img.InputStream.Read(pic, 0, len);
//Upload.PostedFile.InputStream.Read(pic,0,len);
string str = "insert into imageinfo (name,address,photo) values(''" + txtname.Text + "'',''" + txtaddress.Text + "''," + pic + ")";//,photo,@photo
mycmd = new OleDbCommand(str, mycon);
// mycmd.Parameters.AddWithValue("@id", int.Parse(txtid.Text));
mycmd.Parameters.AddWithValue("@name", txtname.Text);
mycmd.Parameters.AddWithValue("@address", txtaddress.Text);
mycmd.Parameters.AddWithValue("@photo", pic);
mycmd.ExecuteNonQuery();
mycon.Close();
lblMessage.Text = "Image details inserted successfully";
Response.Redirect("~/RetriveImage.aspx");
mycon.Close();

解决方案

Read the following:
http://stackoverflow.com/questions/6267159/sql-informix-how-do-i-add-a-blob-when-doing-an-insert-using-the-net-c-s[^]

http://stackoverflow.com/questions/6319858/informix-c-how-do-i-properly-set-unset-a-blob-field[^]

http://stackoverflow.com/questions/3603203/appending-to-informix-blob-without-running-out-of-memory[^]


这篇关于通过c#代码在informix数据库中保存图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆