can't store value of text area in database in comment column it store multiline?

Total Post:117

Points:821
C# 
 1134  View(s)
Ratings:
Rate this:

HTML code

 <textarea id="commentarea" name="S1" cols="30" rows="5"></textarea>

C# code

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString); 
conn.Open(); 
string insertcmnt = "insert into Comment(Comment) values(@comment)"; 
   SqlCommand com = new SqlCommand(insertcmnt, conn);
        com.Parameters.AddWithValue("@comment", TextBoxMode.MultiLine.ToString());
        com.ExecuteNonQuery();
        Response.Write("Commented successfully");
        conn.Close();

  1. Post:101

    Points:709
    Re: can't store value of text area in database in comment column it store multiline?

    Hi jai

    You are storing the name of the MultiLine value from the TextBoxMode enum. You should be referencing the textarea object. Try this

     com.Parameters.AddWithValue("@comment", commentarea.Text);

    Also, the textarea in the html is missing the runat attribute

    <textarea id="commentarea" name="S1" cols="30" rows="5" runat="server"></textarea>

      Modified On Apr-07-2018 05:36:17 AM

Answer