Results 1 to 5 of 5

Thread: Convert VB 6 code to VB.NET Code [resolved]

  1. #1

    Thread Starter
    Addicted Member craigreilly's Avatar
    Join Date
    Jul 2004
    Location
    Scottsdale, AZ
    Posts
    188

    Resolved Convert VB 6 code to VB.NET Code [resolved]

    How do I convert this to VB.NET. Everything I have seen so far needs to create DataAdapters and DataSets.
    Please help. Thanks.
    ==================================
    Dim db As Database
    Dim dblocation As String
    dblocation = App.Path & "\mtb.mdb"
    Set db = OpenDatabase(dblocation)
    Set rsjobs = db.OpenRecordset("jobs", dbOpenTable)

    rsjobs.AddNew
    rsjobs("jobid") = jobid.text
    rsjobs("job name") = jobname.text
    citylen = Len(Text2)
    rsjobs.update

    rsjobs.close
    db.close
    Last edited by craigreilly; Oct 8th, 2004 at 06:25 PM.

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    A simple example of how you can do this in .NET
    VB Code:
    1. Imports System.Data.OleDb
    2.  
    3. Dim Conn As New OleDbConnection(Server.MapPath("mtb.mdb"))
    4. Dim strSql As String = "INSERT INTO jobs VALUES('" & Trim$(jobid.Text) & "', '" & Trim$(jobname.Text) & "')"
    5. Dim Cmd As New OleDbCommand(strSql, Conn)
    6.  
    7. Try
    8.    Conn.Open()
    9.    Cmd.ExecuteNonQuery()  
    10. Catch ex As Exception
    11.    'Catch the error
    12. Finally
    13.    'Close the Conn object
    14.    Conn.Close
    15. End Try
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  3. #3

    Thread Starter
    Addicted Member craigreilly's Avatar
    Join Date
    Jul 2004
    Location
    Scottsdale, AZ
    Posts
    188
    This code produced errors on:

    Code:
    Imports System.Data.OleDb
    Dim Conn As New OleDbConnection(Server.MapPath("mtb.mdb"))
    Dim strSql As String = "INSERT INTO jobs VALUES('" &   _     Trim$(jobid.Text) & "', '" & Trim$(jobname.Text) & "')"
    Dim Cmd As New OleDbCommand(strSql, Conn)
    All 4 lines of code had errors...

  4. #4
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    My mistake, the Dim Conn line should have been like this
    VB Code:
    1. Dim Conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\jobs.mdb;User Id=;Password=;")

    I tested it and it worked fine, none of the other lines caused an error.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  5. #5

    Thread Starter
    Addicted Member craigreilly's Avatar
    Join Date
    Jul 2004
    Location
    Scottsdale, AZ
    Posts
    188
    For the most part - this is what I was looking for... and it works.
    Code:
        Dim sconn As String
        Dim objconn As OleDb.OleDbConnection
        Dim oconn
        Dim sAppPath As String
    
    
        sAppPath = IO.Path.Combine(Application.StartupPath, "mtb.mdb")
    
        sconn = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & sAppPath & "; user id=admin; password="
    
    
    
        objconn = New OleDb.OleDbConnection(sconn)
        objconn.Open()
    
        Dim objcommand As OleDb.OleDbCommand
        Dim objrs As OleDb.OleDbDataReader
    
        objcommand = objconn.CreateCommand
    
               objcommand.CommandText = "SELECT jobs.theid, jobs.jobname, jobs.location, jobs.state, jobs.jobmanager, jobs.status, users.username, users.[full name] FROM jobs,users where jobs.jobmanager=users.theid"
           
    
        objrs = objcommand.ExecuteReader()
    
        While objrs.Read
        end while

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width