params refence wrong textboxes on webform?

R

Rich

Hello,

I have a test aspx page with 2 textboxes which will update
an Access mdb table (which contains several fields but I
work with the following fields):

txtID, txtCity, txtZip

I set param0 to txtID, param1 to txtzip. Then I enter data
in the textboxes (txtID and txtZip) to update the zip
field in a row based on the ID. But when I enter data and
update, param0 references txtZip, param1 references
txtID. Any ideas what is going on? Here is my listing -
Am I missing something? Isn't txtID supposed to be the
first textbox I list and txtZip the second one?:
------------------------------------------------------
<%@ Import Namespace="System.Data.Oledb" %>
<%@ Page Language="VB" Debug="true" %>
<Script Runat="Server">

Sub Button_Click( s As Object, e As EventArgs )
Dim conn As OleDbConnection
Dim cmdUpdate As OleDbCommand
Dim strSql As String

conn = New OleDBconnection
("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
Source=F:\AspNet\db\Members.mdb")

strSql = "Update tblCenter Set Zip=@p1 Where ID=@p0"
cmdUpdate = New OleDbCommand(strSql, conn)

cmdUpdate.Parameters.Add( "@p0", txtID.Text )
cmdUpdate.Parameters.Add( "@p1", txtZip.Text )

conn.Open()
cmdUpdate.ExecuteNonQuery()
conn.Close()

End Sub
</Script>

<html>
<head><title>test1.aspx</title></head>
<body>
<form Runat="Server">
<b>ID:</b>
<asp:TextBox ID="txtID" Runat="Server" />
<br>
<b>Zip:</b>
<asp:TextBox ID="txtZip" Runat="Server" />
<br>
<asp:Button Text="Update" OnClick="Button_Click"
Runat="Server" />
</form>
</body>
</html>
 
R

Rich

I noticed that if I delimit the udpate values in the sql
string (hardcoded) with single quotes, then it works
properly. How can I delimit parameter values?
 
R

Rich

OK. I figured this out. The parameters have to be listed
in the same order as they are listed in the Sql string,
like in the Where clause if the parameter for the Where
clause happens to be the first field in the Table it still
has to be listed at the end of the parameter list.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top