|
|
|
ช่วยแก้ cmd.ExecuteNonQuery(); ให้ด้วยครับ |
|
|
|
|
|
|
|
<%@ Page Language="C#" Debug="true" ContentType="text/html" ResponseEncoding="utf-8" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script runat="server">
void Page_Lond( object sender,EventArgs e){
OleDbConnection con;
OleDbCommand cmd;
OleDbDataReader rdr;
con = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Server.MapPath("spa.mdb"));
con.Open();
cmd = new OleDbCommand ("select userName,password,prefix,fName,lName,address,province,email,hphone,mphone from member",con);
rdr = cmd.ExecuteReader();
grid.DataSource = rdr;
grid.DataBind();
rdr.Close();
con.Close();
}
void insertRecord(object sender,EventArgs e){
OleDbConnection con;
OleDbCommand cmd;
OleDbDataReader rdr;
con = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Server.MapPath("spa.mdb"));
string sql = "INSERT INTO spa(userName,password,prefix,fName,lName,address,province,email,hphone,mphone) VALUES (@User,@Pass,@Pre,@Fname,@Lname,@Add,@Pro,@Emai,@Hpho,@Mpho)";
cmd = new OleDbCommand(sql,con);
cmd.Parameters.Add(new OleDbParameter("@User",txtUser.Text));
cmd.Parameters.Add(new OleDbParameter("@Pass",txtPass.Text));
cmd.Parameters.Add(new OleDbParameter("@Pre",txtPre.Text));
cmd.Parameters.Add(new OleDbParameter("@Fname",txtFname.Text));
cmd.Parameters.Add(new OleDbParameter("@Lname",txtLname.Text));
cmd.Parameters.Add(new OleDbParameter("@Add",txtAdd.Text));
cmd.Parameters.Add(new OleDbParameter("@Pro",txtPro.Text));
cmd.Parameters.Add(new OleDbParameter("@Emai",txtEmai.Text));
cmd.Parameters.Add(new OleDbParameter("@Hpho",txtHpho.Text));
cmd.Parameters.Add(new OleDbParameter("@Mpho",txtMpho.Text));
con.Open();
cmd.ExecuteNonQuery();
con.Close();
label1.Visible=true;
DataBind();
label1.Text = "Your data has been received!";
}
</script>
<html><head><title>Insert into database.</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body style="font:8pt verdana">
<h3>Insert a new row into the database</h3>
<form runat="server">
<table border="0" cellpadding="2" cellspacing="4">
<tr>
<td>USERNAME</td>
<td><asp:TextBox BackColor="#99cc00" ForeColor="#ff0000" ID="txtUser" runat="server" TextMode="SingleLine" /> </td>
</tr>
<tr>
<td>PASSWORD</td>
<td><asp:TextBox BackColor="#99cc00" ForeColor="#FF0000" ID="txtPass" runat="server" TextMode="password" /> </td>
</tr>
<tr>
<td>Prefix</td>
<td><asp:TextBox BackColor="#99cc00" ForeColor="#ff0000" ID="txtPre" runat="server" TextMode="SingleLine"/></td>
</tr>
<tr>
<td>fName</td>
<td><asp:TextBox BackColor="#99cc00" ForeColor="#ff0000" ID="txtFname" runat="server" TextMode="SingleLine"/></td>
</tr>
<tr>
<td>lName</td>
<td><asp:TextBox BackColor="#99cc00" ForeColor="#ff0000" ID="txtLname" runat="server" TextMode="SingleLine"/></td>
</tr>
<tr>
<td>ADDRESS</td>
<td><asp:TextBox BackColor="#99cc00" ForeColor="#ff0000" ID="txtAdd" runat="server" TextMode="SingleLine"/></td>
</tr>
<tr>
<td>province</td>
<td><asp:TextBox BackColor="#99cc00" ForeColor="#ff0000" ID="txtPro" runat="server" TextMode="SingleLine"/></td>
</tr>
<tr>
<td>E-mail</td>
<td><asp:TextBox BackColor="#99cc00" ForeColor="#ff0000" ID="txtEmai" runat="server" TextMode="SingleLine"/></td>
</tr>
<tr>
<td>hPhone</td>
<td><asp:TextBox BackColor="#99cc00" ForeColor="#ff0000" ID="txtHpho" runat="server" TextMode="SingleLine"/></td>
</tr>
<tr>
<td>mPhone</td>
<td><asp:TextBox BackColor="#99cc00" ForeColor="#ff0000" ID="txtMpho" runat="server" TextMode="SingleLine"/></td>
</tr>
<tr>
<td></td>
<td><asp:Button ID="insert" Text="~[ OK ]~" runat="server" OnClick="insertRecord" BorderStyle="groove" /></td>
</tr>
</table>
</form>
<asp:DataGrid ID="grid" Font-Name="Arial" Font-Size="10pt" BackColor="#cccccc"
Width="90%" border="0" CellPadding="5"
runat="server" AutoGenerateColumns="false">
<headerstyle Font-Bold="true" HorizontalAlign="center"/>
<columns>
<asp:BoundColumn DataField="fName" HeaderText="FNAME"/>
<asp:BoundColumn DataField="lName" HeaderText="LNAME"/>
<asp:BoundColumn DataField="address" HeaderText="ADDRESS"/>
<asp:BoundColumn DataField="hphone" HeaderText="HPHONE"/>
</columns>
</asp:DataGrid>
<p><asp:Label ID="lblRecsAff" runat="server" /></p>
<p><asp:Label ID="lblErrMsg" runat="server" /></p>
<p><asp:Label ID="label1" runat="server" /></p>
</body></html>
Tag : - - - -
|
|
|
|
|
|
Date :
2009-02-10 10:11:49 |
By :
devil |
View :
3401 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มัน Error ตรงไหร ยังไงหรือครับ??
|
|
|
|
|
Date :
2009-02-10 13:49:47 |
By :
Zeve |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มัน error ตรงที่ cmd.ExecuteNonQuery(); อะครับ ไม่รู้ว่าเป็นเพราะไรครับ
ผมใช้ C# ครับ เพื่อนๆก็เจอเหมือนกันครับ รบกวนด้วยครับ
|
|
|
|
|
Date :
2009-02-10 15:22:56 |
By :
devil |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
กำ ลืมกระทู้นี้ไปเลยเหอๆ ก็ว่าติดอะไรซักอย่างนึกไม่ออก
Code (C#)
cmd = new OleDbCommand(sql,con);
cmd.CommandType = CommandType.StoredProcedure; // เพิ่มตรงนี้ซิครับ
cmd.Parameters.Add(new OleDbParameter("@User",txtUser.Text));
cmd.Parameters.Add(new OleDbParameter("@Pass",txtPass.Text));
cmd.Parameters.Add(new OleDbParameter("@Pre",txtPre.Text));
cmd.Parameters.Add(new OleDbParameter("@Fname",txtFname.Text));
cmd.Parameters.Add(new OleDbParameter("@Lname",txtLname.Text));
cmd.Parameters.Add(new OleDbParameter("@Add",txtAdd.Text));
cmd.Parameters.Add(new OleDbParameter("@Pro",txtPro.Text));
cmd.Parameters.Add(new OleDbParameter("@Emai",txtEmai.Text));
cmd.Parameters.Add(new OleDbParameter("@Hpho",txtHpho.Text));
cmd.Parameters.Add(new OleDbParameter("@Mpho",txtMpho.Text));
|
|
|
|
|
Date :
2009-02-11 06:43:54 |
By :
Zeve |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|