Connecting Tech Pros Worldwide Help | Site Map

Need to Update Access DB from Visual Basic

Newbie
 
Join Date: Apr 2008
Posts: 11
#1: Jul 10 '09
Good Morning,

Hopefully someone can help me with what I am assuming is a simple query that I simply can't get to work.

I am new to using Visual Basic and I am using Visual Studio 2005, Previously only been working in VBA.

I need to update a field in my database with the changes that are made in my application, I use the following code to call the Record Set.


Expand|Select|Wrap|Line Numbers
  1.       Dim Conn97 As ADODB.Connection
  2.         Dim Path97PRS As String
  3.         Dim rsDetails As New ADODB.Recordset
  4.         Dim strSql As String
  5.  
  6.         Path97PRS = "R:\PRS 97 Version.mdb"
  7.         Conn97 = New ADODB.Connection
  8.         Conn97.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Path97PRS & ";"
  9.         Conn97.Open()
  10.  
  11.         strSql = "SELECT * FROM tbl_workdetails_agb WHERE tbl_WorkDetails_agb.Job_Booking_Referenc = " & Me.Job_Ref.Text
  12.  
  13.         rsDetails.Open(strSql, Conn97, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
  14.  
I then update the record set with the new entries

Expand|Select|Wrap|Line Numbers
  1.  
  2.         rsDetails.Fields("Address").Value = Me.txtAddress.Text
  3.         rsDetails.Fields("Mpan").Value = Me.txtMpan.Text
  4.         rsDetails.Fields("Account_Number").Value = Me.txtAccount.Text
  5.  
But now I need to update the Record Set back into the Database, I tried using the following code

Expand|Select|Wrap|Line Numbers
  1.        strSql = "UPDATE tbl_Workdetails_agb SET Address = Address, Mpan = Mpan,"
  2.         strSql = strSql & " Account_Number = Account_Number WHERE tbl_WorkDetails_agb.Job_Booking_Referenc = " & nbrSelect
  3.         rsDetails = Conn97.Execute(strSql)
  4.  
But alas it simply does nothing, probably becasue I am wiping the record set with my next SQL statement or something. I have tried using the .update command but that simply seems to update the record set again.

Any help would be appreciated.

Thanks

Adam
Newbie
 
Join Date: Apr 2008
Posts: 11
#2: Jul 10 '09

re: Need to Update Access DB from Visual Basic


Think I have it, sorry it appears that I was looking at making it overly complicated
Reply