VB.Net Adding records to a database using code not a datagrid.

I am new to VB.Net but have done some VB6 Programming and alot of VBA Programming.  I have created a program that acts as a stop watch for different tasks that I partake in.  On the Stop Button Click Event I want the Program to record a couple of different things in an access database.  I have been looking for how to add a new record to a table but have yet to come across anything. So far I have OleDataAdapter1, OleDbConnection1, and an dsActivity1 dataset.  Where do I go from here?  Here is a sample of what I got so far:

Private Sub btnOMStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOMStart.Click
        StartTime = Now()
    End Sub

    Private Sub btnOMStop_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOMStop.Click
        StopTime = Now()
        lblResultOM.Text = DateDiff(DateInterval.Second, StartTime, StopTime)
       
    End Sub

Thanks
Mike

LVL 1
EXTRHMANAsked:
Who is Participating?
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.

Jeff CertainCommented:
Mike,

The simplest method is to create an INSERT SQL statement.

Dim conn As OleDbConnection = New OleDbConnection(connectionString)
Dim cmd As OleDbCommand
Dim strSQL as String = "INSERT INTO tableName(columnA,columnB,...) VALUES (value1, value2, ...)"
cmd = New OleDbCommand(strSQL, conn)
cmd.ExecuteNonQuery()
cmd.Dispose()

Jeff
0

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
planoczCommented:
Hi,

Here is where I found good examples for getting started in VB.Net

.....http://msdn.microsoft.com/vbasic/downloads/samples/101samples.aspx

Link for ASP programs...

http://msdn.microsoft.com/asp.net/downloads/kits/default.aspx 


0
EXTRHMANAuthor Commented:
Jeff,

That looks like it will work.

I am getting an error though  "Type "OleDbConnection" not defined" and "Type "OleDbCommand" not defined'

This might sound stupid but am I missing a reference or something/

Thanks
Mike
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Arthur_WoodCommented:
Mike, If you look at Chaosian's code, it is ALMOST line for line the precise equivalent of what you would have done in VB 6, using ADO to connect to the database:

create a ADODB.Connection object, and assign the connection string
Open the Connection object
create an ADODB.Command object, and assign the SQL to the command object
assign the Connection to the command object
then use the Execute method of the Command object to execute the non-record returning SQL
then close the connection, and set it to nothing.

conceptually, the two sequences are identical, the differences are semantics.

AW
0
planoczCommented:
add
Imports System.Data.SqlClient
0
Jeff CertainCommented:
You need to add the line "Imports System.Data.OleDb" at the very top of your class/form. This keeps you from having to type System.Data.OleDB.OleDbConnection, etc.

Importing SQLClient won't help in this case... you're using an Access database.

Jeff
0
Jeff CertainCommented:
Also... forgot to add at the end of the code
conn.Close
to close the database connection.
0
planoczCommented:
Right I forgot his was using access
0
EXTRHMANAuthor Commented:
Thanks for the help.  It works just as planned.
0
Jeff CertainCommented:
Mike,

My pleasure. Been doing too much of that stuff lately, so I had the code more or less handy...

Jeff
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.