ACCESS

How can I accomplish this with Access database? The name of the database is Testonly.mdb The name of the fields are Address, city, state and zip.


 Imports System.Data.SqlClient
Public Class Form2 Inherits System.Windows.Forms.Form
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim ra as Integer
'integer holds the number of records inserted
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e_
As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e_
As System.EventArgs) Handles Button1.Click
myConnection = New SqlConnection("server=localhost;uid=sa;pwd=;database=pubs")
'you need to provide password for sql server
myConnection.Open()
myCommand = New SqlCommand("Insert into Jobs values 12,'IT Manager',100,300,_
myConnection)
ra=myCommand.ExecuteNonQuery()
MessageBox.Show("New Row Inserted" & ra)
myConnection.Close()
End Sub
End Class
VBdotnet2005Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Arthur_WoodCommented:
in Access VBA, this would be:

Dim myConnection As ADODB.Connection
Dim ra as Integer
'integer holds the number of records inserted

Private Sub Button1_Click()

myConnection = CurrentProject.Connection

myConection.Execute("Insert into Jobs values 12,'IT Manager',100,300)

MsgBox "New Row Inserted", vbOkOnly
myConnection = Nothing
End Sub


AW
Arthur_WoodCommented:
That was IN ACCESS, itself.

If you are going to do this from a VB.NET application connecting to a Acceess Back-end Database:

Imports System.Data.OleDb
Public Class Form2 Inherits System.Windows.Forms.Form
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim ra as Integer
'integer holds the number of records inserted
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e_
As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e_
As System.EventArgs) Handles Button1.Click
myConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\testonly.mdb;User Id=admin;Password=;" )

myConnection.Open()
myCommand = New OleDbCommand("Insert into Jobs values 12,'IT Manager',100,300,_
myConnection)
ra=myCommand.ExecuteNonQuery()
MessageBox.Show("New Row Inserted" & ra)
myConnection.Close()
End Sub
End Class

Notice the mimimal nature of the changes (the OleDb objects, and the Connection string)

AW

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VBdotnet2005Author Commented:
Since, Testonly.mdb is a database file, do I still need to provide user name and password?
KudzullcCommented:
<<"Since, Testonly.mdb is a database file, do I still need to provide user name and password? >>

Only if you have manually set one up inside Access.  If you have only a password, you can leave off the "User Id=;".

Lucas
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.