Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics 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 October 19th, 2006, 04:27 AM
Authorized User
 
Join Date: Aug 2006
Location: san fernando, la union, , Philippines.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default vb6 to vb.NET

hi everyone!

i'm rather new to vb.NET. i'm trying to migrate from vb6 to vb.NET. i've got visual studio 2003 installed. my problem is this:

in vb6 i use this code for a method in a class (clsVehicles):
------------------------------------------------------------
Option Explicit

Dim conDB As ADODB.Connection
Dim strSQL As String

Private Sub Class_Initialize()
Set conDB = New ADODB.Connection
conDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
         "Data Source =D:\LUECO\MPCS\MotorPool.mdb"
End Sub

Private Sub Class_Terminate()
Set conDB = Nothing
End Sub

Public Function Add_Vehicle(ByVal strUnitNo As String, _
                            ByVal strVtype As String, _
                            ByVal strPlateNo As String, _
                            ByVal strRegCert As String, _
                            ByVal dtExpiry As Date, _
                            ByVal strDriver1 As String, _
                            ByVal strDriver2 As String) As Boolean
Dim rsVehicle As New ADODB.Recordset

On Error GoTo ErrHandler

conDB.Open
conDB.CursorLocation = adUseServer

strSQL = "SELECT * FROM vehicles WHERE 1=2"
rsVehicle.Open strSQL, conDB, adOpenKeyset, adLockOptimistic

conDB.BeginTrans
With rsVehicle
   .AddNew
   .Fields("Unit_No") = strUnitNo
   .Fields("Vehicle_Type") = strVtype
   .Fields("Plate_No") = strPlateNo
   .Fields("LTO_Reg_No") = strRegCert
   .Fields("Expiry_Date") = dtExpiry
   .Fields("Driver_1") = strDriver1
   .Fields("Driver_2") = strDriver2
   .Update
End With
conDB.CommitTrans
Add_Vehicle = True
conDB.Close
Exit Function

ErrHandler:
   Debug.Print "Error : " & Err.Number & " - " & Err.Description
   conDB.RollbackTrans
   conDB.Close
   Add_Vehicle = False
End Function
-------------------------------
i would like to convert the code to vb.NET (2003 version)
would anyone show me how?

thanks a lot

jorge


Reply With Quote
  #2 (permalink)  
Old October 24th, 2006, 04:55 AM
Registered User
 
Join Date: Oct 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There are two things that I would mention. I would have

Option Strict On
Option Explicit On

This should help with the transition. Secondly, don't use On Error in .NET. It's a legacy VB6 thing.

Use something like this instead:

Code:
Try
  conDB.Open
  conDB.CursorLocation = adUseServer

   strSQL = "SELECT * FROM vehicles WHERE 1=2"
   rsVehicle.Open strSQL, conDB, adOpenKeyset, adLockOptimistic

   conDB.BeginTrans
   With rsVehicle
    .AddNew
    .Fields("Unit_No") = strUnitNo
    .Fields("Vehicle_Type") = strVtype
    .Fields("Plate_No") = strPlateNo
    .Fields("LTO_Reg_No") = strRegCert
    .Fields("Expiry_Date") = dtExpiry
    .Fields("Driver_1") = strDriver1
    .Fields("Driver_2") = strDriver2
    .Update
   End With
  conDB.CommitTrans
  Add_Vehicle = True

Catch ex As Exception
   messagebox.Show(ex.message)
   conDB.RollbackTrans
   Add_Vehicle = False

Finally
   conDB.Close

End Try
Although 2003 should have a converter to help you when you import code.

Stim

Reply With Quote
  #3 (permalink)  
Old October 26th, 2006, 05:05 AM
Authorized User
 
Join Date: Aug 2006
Location: san fernando, la union, , Philippines.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Stim, this would help. I'll try it.


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
Consume VB6.0 WebService in ASP.NET using VB.NET pinkarc .NET Web Services 1 March 5th, 2007 08:19 AM
Should I go VB.NET or VB 2005 from VB6? HB Visual Studio 2005 1 December 9th, 2005 03:13 AM
VB6 vs VB .Net ioates VB.NET 2002/2003 Basics 2 January 7th, 2004 12:55 PM
VB6 vs VB.Net ioates Pro VB.NET 2002/2003 4 December 29th, 2003 10:30 AM
VB6 and VB.Net ioates VB.NET 2002/2003 Basics 1 December 9th, 2003 05:25 AM



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


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