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
Register
| 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
Reply
 
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

hi,

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.

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

<html>
<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)
cn.Open()

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")
TextBox2.text=dr("DESIGNATION")
TextBox3.text=dr("CONTACTNO")
TextBox4.text=dr("EMAIL")
TextBox5.text=dr("USERNAME")
TextBox6.text=dr("PWD")
end if
end while
cmd.dispose()
cn.close()
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"
response.write(lblRecsAff.text)
lblRecsAff.Text = ""
dbstring = "user id=sa;password=admin;server=.;initial catalog=students"
conClasf = New SqlConnection(dbstring)
conClasf.open()
strSQL = "UPDATE TEACHERS SET TNAME='"& TextBox1.Text &"' where TID ='"& str &"' "
response.Write(strsql)
Dim cmd As New SqlCommand(strSQL,conClasf)
cmd.ExecuteNonQuery()
cmd.Dispose()
conClasf.Close()
end sub
</script>
</HEAD>
<body>
<form action="edit.aspx" method="post" name="form1" runat="server" ID="Form2">
<DIV align=center>
<TABLE cellSpacing=0 cellPadding=0 width=800 border=0>
<TBODY>
<TR>
<TD width=768 height=416 vAlign=top><BR>
<TABLE cellSpacing=0 cellPadding=2 width=550 align=center border=0>
<TBODY>
<TR>
<TD class=OUTERTABLE vAlign=top>
<TABLE class=INNERTABLE-WHITE cellSpacing=1 cellPadding=1
width="98%" align=center border=0>

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

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

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


  </p>
  </TD>
<TD class=whitebg width=42></TD></TR>
<TR>
<TD class=whitebg width=221>*
Designation</TD>
<TD class=whitebg width=242><asp:TextBox ID="TextBox2" runat="server" />
</TD>
<TD class=whitebg width=42></TD></TR>
<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>
<TR>
<TD class=whitebg width=221>*
Email</TD>
<TD class=whitebg width=242>
  <asp:TextBox ID="TextBox4" runat="server" /></TD>
<TD class=whitebg width=42></TD></TR>
<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>
<TR>
<TD class=whitebg width=221>*
Password</TD>
<TD class=whitebg width=242>
  <asp:TextBox ID="TextBox6" runat="server" /></TD>
<TD class=whitebg width=42></TD></TR>
<TR>
<TD class=whitebg width=221></TD>
<TD class=whitebg width=242></TD>
<TD class=whitebg width=42></TD></TR>
<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>
<TD class=whitebg width=42></TD>
</TR></TBODY>
</TABLE></TD>
<TD></TD>
</TR>
<TR>
<TD height=0></TD>
<TD></TD>
<TD></TD>
</TR>
</TBODY></TABLE></TD></TR>
<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>
</TR>
<TR>
<TD height=172>&nbsp;</TD>
<TD>&nbsp;</TD>
</TR>
</TBODY></TABLE>
</DIV>
</form>
    </body>
</HTML>
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
Default

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.

-Peter
Reply With Quote
Reply


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.