001.
<%@ Page Language=
"C#"
Debug=
"true"
%>
002.
<%@ import Namespace=
"System.Data"
%>
003.
<%@ import Namespace=
"MySql.Data.MySqlClient"
%>
004.
<script runat=
"server"
>
005.
006.
void
Page_Load(
object
sender,EventArgs e)
007.
{
008.
009.
}
010.
011.
void
btnSave_Click(Object sender , EventArgs e)
012.
{
013.
MySqlConnection objConn =
new
MySqlConnection();
014.
MySqlCommand objCmd =
new
MySqlCommand();
015.
String strConnString,strSQL;
016.
017.
strConnString =
"Server=localhost;User Id=root; Password=root; Database=mydatabase; Pooling=false"
;
018.
019.
strSQL =
"INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) "
+
020.
" VALUES "
+
021.
" ('"
+
this
.txtCustomerID.Text +
"','"
+
this
.txtName.Text +
"','"
+
this
.txtEmail.Text +
"', "
+
022.
" '"
+
this
.txtCountryCode.Text +
"','"
+
this
.txtBudget.Text +
"','"
+
this
.txtUsed.Text +
"')"
;
023.
objConn.ConnectionString = strConnString;
024.
objConn.Open();
025.
objCmd.Connection = objConn;
026.
objCmd.CommandText = strSQL;
027.
objCmd.CommandType = CommandType.Text;
028.
029.
030.
this
.pnlAdd.Visible =
false
;
031.
032.
try
033.
{
034.
objCmd.ExecuteNonQuery();
035.
this
.lblStatus.Text =
"Record Inserted"
;
036.
this
.lblStatus.Visible =
true
;
037.
}
038.
catch
(Exception ex)
039.
{
040.
this
.lblStatus.Visible =
true
;
041.
this
.lblStatus.Text =
"Record can not insert Error ("
+ ex.Message +
")"
;
042.
}
043.
044.
objConn.Close();
045.
objConn =
null
;
046.
047.
}
048.
049.
</script>
050.
<html>
051.
<head>
052.
<title>ThaiCreate.Com ASP.NET - MySql</title>
053.
</head>
054.
<body>
055.
<form id=
"form1"
runat=
"server"
>
056.
<asp:Panel id=
"pnlAdd"
runat=
"server"
>
057.
<table width=
"353"
border=
"1"
>
058.
<tbody>
059.
<tr>
060.
<td width=
"102"
>
061.
<asp:Label id=
"lblCustomerID"
runat=
"server"
text=
"CustomerID"
></asp:Label></td>
062.
<td width=
"235"
>
063.
<asp:TextBox id=
"txtCustomerID"
runat=
"server"
Width=
"79px"
></asp:TextBox>
064.
</td>
065.
</tr>
066.
<tr>
067.
<td>
068.
<asp:Label id=
"lblName"
runat=
"server"
text=
"Name"
></asp:Label></td>
069.
<td>
070.
<asp:TextBox id=
"txtName"
runat=
"server"
Width=
"177px"
></asp:TextBox>
071.
</td>
072.
</tr>
073.
<tr>
074.
<td>
075.
<asp:Label id=
"lblEmail"
runat=
"server"
text=
"Email"
></asp:Label></td>
076.
<td>
077.
<asp:TextBox id=
"txtEmail"
runat=
"server"
Width=
"155px"
></asp:TextBox>
078.
</td>
079.
</tr>
080.
<tr>
081.
<td>
082.
<asp:Label id=
"lblCountryCode"
runat=
"server"
text=
"CountryCode"
></asp:Label></td>
083.
<td>
084.
<asp:TextBox id=
"txtCountryCode"
runat=
"server"
Width=
"38px"
></asp:TextBox>
085.
</td>
086.
</tr>
087.
<tr>
088.
<td>
089.
<asp:Label id=
"lblBudget"
runat=
"server"
text=
"Budget"
></asp:Label></td>
090.
<td>
091.
<asp:TextBox id=
"txtBudget"
runat=
"server"
Width=
"76px"
></asp:TextBox>
092.
</td>
093.
</tr>
094.
<tr>
095.
<td>
096.
<asp:Label id=
"lblUsed"
runat=
"server"
text=
"Used"
></asp:Label></td>
097.
<td>
098.
<asp:TextBox id=
"txtUsed"
runat=
"server"
Width=
"76px"
></asp:TextBox>
099.
</td>
100.
</tr>
101.
</tbody>
102.
</table>
103.
<br />
104.
<asp:Button id=
"btnSave"
onclick=
"btnSave_Click"
runat=
"server"
Text=
"Save"
></asp:Button>
105.
<br />
106.
</asp:Panel>
107.
<asp:Label id=
"lblStatus"
runat=
"server"
visible=
"False"
></asp:Label>
108.
</form>
109.
</body>
110.
</html>