【发布时间】:2013-01-24 16:14:22
【问题描述】:
我在将图像保存到我的数据库时遇到问题。 我不知道如何将图像插入或存储到我的数据库中并显示在我的网格视图中。
这是我的桌子设计:
在我的网络方法中:
[WebMethod(EnableSession = true)]
public string sell_item(string name, Image photo, string description)
{
SqlConnection con = new SqlConnection("Data Source=USER-PC;Initial Catalog=Bidding;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("UPDATE login SET name = @name, photo = @photo, description = @description WHERE username=@username", con);
cmd.Parameters.AddWithValue("@name", name);
cmd.Parameters.AddWithValue("@photo", photo);
cmd.Parameters.AddWithValue("@description", description);
cmd.ExecuteNonQuery();
con.Close();
return "Product has been upload successfully!";
}
我在 Web 应用程序中调用 Web 服务的代码:
我使用 FileUpload 按钮来选择我的图像文件。
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = Convert.ToString(a.sell_item(Convert.ToString(TextBoxName.Text), Convert.ToString(FileUploadPhoto.FileName), Convert.ToString(TextBoxDescription.Text)));
Label1.Visible = true;
if (Label1.Visible == true)
{
MessageBox.Show("Item has been uploaded successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
Response.Redirect("Menu page.aspx");
}
}
在我的 gridview 中,我设置了属性:
图像不会显示在网格视图中。 我还是 c# 的新手。任何人都可以帮助我吗?谢谢。
【问题讨论】: