Insert Data in Parameterise to Database using Asp.net webui
C# Code
protected void btnSave_Click(object sender, EventArgs e)
{
string Vission = txtvision.InnerText;
string Mission = txtmission.InnerText;
string values = txtvalues.InnerText;
string status = ddlStatus.SelectedValue;
if (Vission != "<br>" && Mission != "<br>" && values != "<br>" && status != "")
{
MySqlConnection con = new MySqlConnection(conStr);
string str = "insert into vision_mst(vision_text,mission_text,values_text,vision_status,added_on,added_by) values(@Vission,@Mission,@values,@status,now(),'" + Session["USER_ID"].ToString() + "')";
MySqlCommand cmd = new MySqlCommand(str,con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Vission", Vission);
cmd.Parameters.AddWithValue("@Mission", Mission);
cmd.Parameters.AddWithValue("@values", values);
cmd.Parameters.AddWithValue("@status", status);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
if (i > 0)
{
lblMsg.Text = "Record has been added succesfully";
lblMsg.CssClass = "successMsg";
}
else
{
lblMsg.Text = "Error in record insertion";
lblMsg.CssClass = "errorMsg";
}
txtvision.InnerText = "";
txtmission.InnerText = "";
txtvalues.InnerText = "";
ddlStatus.SelectedIndex = 0;
}
else
{
lblMsg.Text = "Please enter text in Mandatory Fields";
lblMsg.CssClass = "errorMsg";
}
}
ASP.Net
<%@ Page Title="vision Add" Language="C#" MasterPageFile="~/Admin.Master" AutoEventWireup="true" CodeBehind="VisionAddition.aspx.cs" Inherits="CationHRManagementSystem.VisionAddition" ValidateRequest="false" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<link href="css/cssCommon.css" rel="stylesheet" />
<script type="text/javascript" src="http://js.nicedit.com/nicEdit-latest.js"></script>
<script type="text/javascript">
//<![CDATA[
bkLib.onDomLoaded(function () { nicEditors.allTextAreas() });
//]]>
</script>
<div>
<table width="100%" style="background-color: lightgray;">
<tr>
<td width="100%" class="pageHeadertext-style">Vision: Create</td>
</tr>
</table>
<table style="margin-left: 40px; margin-top: 40px; margin-bottom: 40px;">
<tr>
<td></td>
<td align="right">
<asp:Button ID="btnBack" runat="server" Text="Back" OnClick="btnBack_Click" Style="margin-left: 0px" CssClass="button-style" />
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Label ID="lblMsg" runat="server" CssClass="labeltext-style"></asp:Label>
</td>
</tr>
<%-- <tr>
<td class="text-style"> Organization</td>
<td>
<asp:TextBox ID="txtOrg" runat="server" CssClass="textbox-style"></asp:TextBox>
</td>
</tr>--%>
<tr>
<td class="textfield xui-required" align="right">Vision<%--<span class="redTxt">* </span>--%></td>
<td>
<textarea id="txtvision" runat="server" rows="5" cols="55" class="EULAtextarea-style"></textarea>
</td>
</tr>
<tr>
<td class="textfield xui-required" align="right">Mission<%--<span class="redTxt">* </span>--%></td>
<td>
<textarea id="txtmission" runat="server" rows="5" cols="55" class="EULAtextarea-style"></textarea>
</td>
</tr>
<tr>
<td class="textfield xui-required" align="right">Value<%--<span class="redTxt">* </span>--%></td>
<td>
<textarea id="txtvalues" runat="server" rows="8" cols="55" class="EULAtextarea-style"></textarea>
</td>
</tr>
<tr>
<td class="textfield xui-required" align="right">Status <%--<span class="redTxt">* </span>--%></td>
<td>
<asp:DropDownList ID="ddlStatus" runat="server" CssClass="dropdownsmall-style">
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" CssClass="button-style" ></asp:Button>
<%--<asp:Button ID="btnReset" runat="server" Text="Reset" OnClick="btnReset_Click" CssClass="button-style"></asp:Button>--%>
</td>
</tr>
</table>
</div>
</asp:Content>
Output