データベースへの画像の保存に問題があります。画像をデータベースに挿入または保存し、グリッドビューに表示する方法がわかりません。
私のテーブルのデザインは次のとおりです。
私のWebメソッドでは:
[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");
}
}
私のグリッドビューでは、プロパティを設定しました:
画像はグリッドビューに表示されません。私はまだC#に不慣れです。誰でも私を助けることができますか?ありがとう。