Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 7th, 2006, 05:37 PM
Authorized User
Join Date: Jan 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Update Statement some error


following is the code for editing.The problem is in the Onclick of edit button.The values are not getting updated.I tried updating the
textbox1's value.and i tried printing too.But its not working.
The output is the following.Say i am inputing value 20 in the
textbox1.But the value 20 doesnt get passed in the update statement.

'This is the UPDATE statement.
strSQL = "UPDATE TEACHERS SET TNAME='"& TextBox1.Text &"' where TID ='"& str &"' "

<script language="vb" runat="server">
Sub Page_Load
dim cv as string
dim username as string
dim email as string
dim sname as string
dim str as string

Dim strConnection As String = "user id=sa;password=admin;server=.;initial catalog=students"
Dim cn As SqlConnection = New SqlConnection(strConnection)

str = (request.querystring("cv"))
Dim strSelect As String = _
        "SELECT * FROM teachers"
Dim cmd As SqlCommand = New SqlCommand(strSelect, cn)
Dim dr As SqlDataReader
dr = cmd.ExecuteReader()
while dr.Read
if str=dr("TID") then
TextBox1.Text = dr("TNAME")
end if
end while
end sub

Sub edit(s As Object, e As EventArgs)
dim str as string
dim cv as string
dim p as string
Dim conClasf As SqlConnection
Dim dbstring As String
Dim strSQL As String
dim tid as string
str = (request.querystring("cv"))
lblRecsAff.Text = "hi"
lblRecsAff.Text = ""
dbstring = "user id=sa;password=admin;server=.;initial catalog=students"
conClasf = New SqlConnection(dbstring)
strSQL = "UPDATE TEACHERS SET TNAME='"& TextBox1.Text &"' where TID ='"& str &"' "
Dim cmd As New SqlCommand(strSQL,conClasf)
end sub
<form action="edit.aspx" method="post" name="form1" runat="server" ID="Form2">
<DIV align=center>
<TABLE cellSpacing=0 cellPadding=0 width=800 border=0>
<TD width=768 height=416 vAlign=top><BR>
<TABLE cellSpacing=0 cellPadding=2 width=550 align=center border=0>
<TD class=OUTERTABLE vAlign=top>
<TABLE class=INNERTABLE-WHITE cellSpacing=1 cellPadding=1
width="98%" align=center border=0>

<TD width="1" height=11></TD>
<TD width="522"></TD>
<TD width="5"></TD>
<TD height=215></TD>
<TD vAlign=top>
<TABLE cellSpacing=1 cellPadding=1 width=525 border=0>

<TD class=HeadingTable width=517 colSpan=3>Edit
<TD class=Heading2 width=517 colSpan=3>&nbsp;</TD></TR>
<TD class=whitebg width=221>*
Teacher Name</TD>
<TD class=whitebg width=242>

    <asp:TextBox ID="TextBox1" runat="server" />

<TD class=whitebg width=42></TD></TR>
<TD class=whitebg width=221>*
<TD class=whitebg width=242><asp:TextBox ID="TextBox2" runat="server" />
<TD class=whitebg width=42></TD></TR>
<TD class=whitebg width=221>*
Contact no's</TD>
<TD class=whitebg width=242>
  <asp:TextBox ID="TextBox3" runat="server" /></TD>
<TD class=whitebg width=42></TD></TR>
<TD class=whitebg width=221>*
<TD class=whitebg width=242>
  <asp:TextBox ID="TextBox4" runat="server" /></TD>
<TD class=whitebg width=42></TD></TR>
<TD class=whitebg width=221>*
User Name</TD>
<TD class=whitebg width=242>
  <asp:TextBox ID="TextBox5" runat="server" /> </TD>
<TD class=whitebg width=42></TD></TR>
<TD class=whitebg width=221>*
<TD class=whitebg width=242>
  <asp:TextBox ID="TextBox6" runat="server" /></TD>
<TD class=whitebg width=42></TD></TR>
<TD class=whitebg width=221></TD>
<TD class=whitebg width=242></TD>
<TD class=whitebg width=42></TD></TR>
<TD class=whitebg width=221></TD>
<TD class=whitebg width=242>
   <asp:Button ID="Button1" Text="Edit" onclick="edit" runat="server"/>
   <asp:Button ID="Button2" text="Cancel" runat="server" />
<TD class=whitebg width=42></TD>
<TD height=0></TD>
<TR><asp:Label ID="lblRecsAff" runat="server" />
<TD class=OUTERTABLE height=3></TD></TR></TBODY></TABLE>
<P>&nbsp;</P> <BR> <BR></TD>
<TD width=32>&nbsp;</TD>
<TD height=172>&nbsp;</TD>
Reply With Quote
  #2 (permalink)  
Old January 8th, 2006, 10:30 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

It look like the problem is that you are re-populating the textbox values on every page hit. Remember one of the fundamentals of ASP.NET: Every page hit at the server is a unique and independant page request. The server only knows the difference between each page request based on the post data. You need to check for IsPostback in your page load and only load the textboxes on the first page hit.

In page_load():

If Not IsPostback Then
   <do your textbox prefill from DB here>
End If

Now, when you click the update button, that prefill part won't run and you'll actually be updating with the values you manually enter.

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
T-SQL statement causing error with insert/update saf SQL Language 0 September 7th, 2007 04:48 PM
Error when trying to use an UPDATE statement wayne62682 Access VBA 2 April 4th, 2006 07:50 PM
Syntax Error in the update statement annie_t Access ASP 1 February 1st, 2005 12:48 PM
UPDATE statement returns syntax error AviatorTim Classic ASP Databases 2 January 8th, 2004 05:22 PM

All times are GMT -4. The time now is 11:56 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.