I have a ASP.Net Page with code behined in C#. as below
I am try to send the Customer name entered to a SQL DB but I am not sure how to process this on the C# page. I am new to this and do not quite understand. I have been able to retrive data in other apps but I can not seem to write to a SQL DB. Below is what I have in the code behind.
Code:
<body>
<form id="form1" runat="server">
<table align=center >
<tr>
<td>
<asp:Label runat=server ID="lblCustomer">Customer Name: </asp:Label>
<asp:TextBox Style="color:Red" runat=server ID="txtCustomer" OnFocus="clearDefault(this)">Enter Customer Name</asp:TextBox>   
<asp:Button runat=server ID=cmdSubmit OnClick="cmdSubmit" Text="Create Customer"/>
</td>
</tr>
</table>
</form>
</body>
</html>
Code:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Conversion_Tool.Classes;
namespace Conversioin_Tool
{
public partial class CustomerCreation : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
cmdCustomer_Click += new System.EventHandler(this.cmdCustomer_Click);
}
protected void cmdCustomer_Click(object sender, EventArgs e)
{
CustomerInsert(txtCustomer.Text).ToString;
}
protected void CustomerInsert(string Customer)
{
string SQLStr = "Insert into CT_Customers" +
" (Customer)" +
" Values('" + sCustomer + "')";
SqlConnection SqlConn = new SqlConnection (ConfigurationManager.ConnectionStrings["Conversion_Tool"].ToString());
try
{
//Try to open connection
SQLConn.Open();
//SQL Adapter
SqlDataAdapter da = new SqlDataAdapter(SQLStr, SqlConn);
//Cose Connection
SqlConn.Close();
}
}
}
}
Comment