|
-
Jul 11th, 2004, 03:30 PM
#1
Thread Starter
Addicted Member
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.
-
Jul 11th, 2004, 03:57 PM
#2
Frenzied Member
A simple example of how you can do this in .NET
VB 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)
Try
Conn.Open()
Cmd.ExecuteNonQuery()
Catch ex As Exception
'Catch the error
Finally
'Close the Conn object
Conn.Close
End Try
Being educated does not make you intelligent.
Need a weekend getaway??? Come Visit
-
Jul 11th, 2004, 04:53 PM
#3
Thread Starter
Addicted Member
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...
-
Jul 11th, 2004, 09:55 PM
#4
Frenzied Member
My mistake, the Dim Conn line should have been like this
VB Code:
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
-
Jul 18th, 2004, 07:40 PM
#5
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|