Dear sir,
i am try to insert value from textarea, Label and image.
namespace OCMS
{
public partial class It_Comp : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lblName.Text = " " + Request.QueryString["EmpId"] + "";
}
if (!Page.IsPostBack)
{
BindGrid();
}
}
private void SaveImage()
{
if (FileUpload1.HasFile)
{
int imagefilelenth = FileUpload1.PostedFile.ContentLength;
byte[] imgarray = new byte[imagefilelenth];
HttpPostedFile image = FileUpload1.PostedFile;
image.InputStream.Read(imgarray, 0, imagefilelenth);
SqlConnection con = new SqlConnection(@"Data Source=(localdb)\Projects;Initial Catalog=OCMS;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False");
SqlCommand cmd = new SqlCommand("Insert into IT_comp_box (EmpCode, COMP_MESSAGE,Image) values (@lblName.text, @str,@Image)", con);
con.Open();
cmd.Parameters.AddWithValue("@lblName", SqlDbType.VarChar).Value = lblName.Text;
// cmd.Parameters.AddWithValue("@str", SqlDbType.varchar).Value = str.Text.ToString();
cmd.Parameters.Add("@str", SqlDbType.VarChar).Value = str.Text.ToString();
cmd.Parameters.AddWithValue("@Image", SqlDbType.Image).Value = imgarray;
cmd.ExecuteNonQuery();
BindGrid();
}
}
public void BindGrid()
{
SqlConnection con = new SqlConnection(@"Data Source=(localdb)\Projects;Initial Catalog=OCMS;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False");
SqlCommand cmd = new SqlCommand("Select COMP_ID,EmpCode,COMP_MESSAGE,COMP_LODGE_DATE,CLOSING_DATE from IT_comp_box", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
SaveImage();
}
}
}
<h4>Image File:</h4>
<asp:FileUpload ID="FileUpload1" runat="server" />
<center>
<u><h3 align="left">COMPLAINT BOX :</h3></u>
</center>
<center><b>COMPLAINT MESSAGE </b></center>
<textarea id="str" cols="20" TextMode="MultiLine" Rows="5" maxlength="640"
style="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #72A4D2; height: 142px; width: 553px;"></textarea>
<center><asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click"></asp:Button>
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'str' does not exist in the current context
Source Error:
|
Line 52: cmd.Parameters.AddWithValue("@lblName", SqlDbType.VarChar).Value = lblName.Text;
Line 53: // cmd.Parameters.AddWithValue("@str", SqlDbType.varchar).Value = str.Text.ToString();
Line 54: cmd.Parameters.Add("@str", SqlDbType.VarChar).Value = str.Text.ToString();
Line 55: cmd.Parameters.AddWithValue("@Image", SqlDbType.Image).Value = imgarray;
Line 56: cmd.ExecuteNonQuery();
|