Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 25th, 2006, 11:49 AM
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Updating the record in the database

Can you please help me.
Here is my code, it's not giving any error but it does not update the field in the database.

Dim strCnx As String = AccessCnx()
Dim strSQL As String = "SELECT * FROM Schedule"
Dim cnx As OleDbConnection = New OleDbConnection(strCnx)
cnx.Open()

Dim ds As Dataset = New DataSet
Dim sda as OleDbDataAdapter
sda= New OleDbDataAdapter(strSQL, cnx)
sda.Fill(ds, "Schedule")
Dim datarow1 As DataRow
Dim scb as OledbCommandBuilder = New OleDbCommandBuilder(sda)
sda.UpdateCommand = scb.GetUpdateCommand()

 For each datarow1 in ds.Tables("Schedule").Rows
  LL.Text=LL.Text & "<br>--" & datarow1("mo_ye") ' this line works OK
    datarow1.BeginEdit()
     datarow1("mo_ye")="33333" '??this line does not update the value
    datarow1.EndEdit()
  Next

 ds.AcceptChanges()
 sda.Update(ds, "Schedule")
 cnx.Close

Many thanks in advance.
 
Old February 26th, 2006, 08:28 PM
Wrox Technical Editor
 
Join Date: Dec 2005
Location: , , Canada.
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Just as you have your SQL SELECT statement, you must also have an SQL UPDATE statement.
Your OleDbDataAdapter has a SelectCommand set through the OleDbDataAdapter(strSQL, cnx) constructor; however you don't have a corresponding UpdateCommand assigned.

You'll need something like:

sda.UpdateCommand = new OleDbCommand("UPDATE something SET something = @Something WHERE something = something", conn)

More info on the OleDbDataAdapter.UpdateCommand Property:
http://msdn.microsoft.com/library/de...mmandtopic.asp

- A.Kahtava
 
Old February 27th, 2006, 01:58 PM
Registered User
 
Join Date: Feb 2006
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks very much. I have to learn and play with it a little more.
But I was looking for the way to do similar like in ASP

In ASP we could do
  rst("fieldname")=value
  rst.Movenext

instead of writing sql statement, which can be very long if a lot of fields should be updated.

So I thought about something similar in asp.net.
Thanks a lot.







 
Old February 28th, 2006, 07:57 AM
Wrox Technical Editor
 
Join Date: Dec 2005
Location: , , Canada.
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ASP to ASP.NET is a fairly steep learning curve, but the benifits are huge.
It's best to approach ASP.NET & ADO.NET as a whole new concept with a couple syntactical similarities to ASP.

- A.Kahtava




Similar Threads
Thread Thread Starter Forum Replies Last Post
updating database after record deletion marcstrong Visual Basic 2008 Essentials 1 July 22nd, 2008 05:25 PM
Updating database record shrisangeeta Classic ASP Basics 4 February 28th, 2007 05:25 PM
ASP.NET 2.0 Updating Database Record columth06 ASP.NET 2.0 Basics 0 November 4th, 2006 07:43 AM
Updating the record in database lwebzem ASP.NET 1.0 and 1.1 Basics 4 March 8th, 2006 09:40 AM
Record not updating Tangerine ASP.NET 1.x and 2.0 Application Design 3 March 24th, 2004 12:00 PM





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