如何使用 C# 代码将图像保存在 Informix 数据库中?
目前,我无法使用 C# 代码将图像保存在 Informix 数据库中。
所有步骤都有效,只有在查询即将执行时才会抛出错误“E42000:(-201)发生语法错误”。
下面是代码。
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();