Hi amar,
Please take reference the below code and correct your code.
HTML
<script type="text/javascript" src="//tinymce.cachefly.net/4.0/tinymce.min.js"></script>
<script type="text/javascript">
tinymce.init({
selector: 'textarea',
width: 500,
readonly: 1
});
</script>
<asp:TextBox ID="txtHTMLContent" runat="server" TextMode="MultiLine" />
<br />
<asp:Button ID="btnSubmit" Text="Submit" runat="server" OnClick="Submit" />
Namespaces
C#
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string query = "SELECT [Content] FROM [HTMLContent]";
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand(query, con))
{
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
if (sdr.Read())
{
txtHTMLContent.Text = sdr["Content"].ToString();
}
sdr.Close();
}
con.Close();
}
}
}
}
protected void Submit(object sender, EventArgs e)
{
string query = "INSERT INTO [HTMLContent] VALUES (@Content)";
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand(query, con))
{
cmd.Parameters.AddWithValue("@Content", txtHTMLContent.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Response.Redirect("~/CS.aspx");
}
}
}
Screenshot