p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 1.0 and 1.1 Basics (http://p2p.wrox.com/forumdisplay.php?f=60)
-   -   Updating the record in the database (http://p2p.wrox.com/showthread.php?t=39025)

lwebzem February 25th, 2006 11:49 AM

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.

adam_kahtava February 26th, 2006 08:28 PM

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

lwebzem February 27th, 2006 01:58 PM

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.








adam_kahtava February 28th, 2006 07:57 AM

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


All times are GMT -4. The time now is 01:46 PM.

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