我正在尝试将图像上传到sql server 2008 [英] im trying to upload an image into sql server 2008
本文介绍了我正在尝试将图像上传到sql server 2008的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我在表单中想要显示图像的代码,但是我在下面的代码"storeimage.ExecuteNonQuery();
"中收到错误消息,提示"Incorrect syntax near image content
"
This is the code that i have in my form where i want to display the image but i get an error in the code "storeimage.ExecuteNonQuery();
" below that says "Incorrect syntax near image content
"
protected void btnadd_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile != null
&& FileUpload1.PostedFile.FileName != "")
{
byte[] myimage = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile Image = FileUpload1.PostedFile;
Image.InputStream.Read(myimage, 0, (int)FileUpload1.PostedFile.ContentLength);
SqlConnection myConnection = new SqlConnection("Data Source=MAC-PC\\SQLEXPRESS;Initial Catalog=Populate_Pictures;Integrated Security=True");
SqlCommand storeimage = new SqlCommand("Insert_into_Populate_pictures"
+ "(image_content,image_type,image_size)"
+ "values(@image_content,@image_type,@image_size)", myConnection);
storeimage.Parameters.Add("@image_content", SqlDbType.Image, myimage.Length).Value = myimage;
storeimage.Parameters.Add("@imagtype", SqlDbType.VarChar, 100).Value
= FileUpload1.PostedFile.ContentType;
storeimage.Parameters.Add("@imagesize", SqlDbType.BigInt, 9999).Value
= FileUpload1.PostedFile.ContentLength;
myConnection.Open();
storeimage.ExecuteNonQuery();
myConnection.Close();
GridView1.DataSource = FetchAllImagesInfo();
GridView1.DataBind();
}
}
public DataTable FetchAllImagesInfo()
{
string sql="Select * from Candidate_Images";
SqlDataAdapter da = new SqlDataAdapter(sql, "Data Source=MAC-PC\\SQLEXPRESS;Initial Catalog=Populate_Pictures;Integrated Security=True");
DataTable dt= new DataTable ();
da.Fill(dt);
return dt;
}
}
推荐答案
您需要如下所示的空格:
You need spaces as shown:
+
" (image_content,image_type,image_size) "
^ ^
这篇关于我正在尝试将图像上传到sql server 2008的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文