EXTRHMAN
asked on
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.Seco nd, StartTime, StopTime)
End Sub
Thanks
Mike
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.Seco
End Sub
Thanks
Mike
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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
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
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
add
Imports System.Data.SqlClient
Imports System.Data.SqlClient
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.OleDbCon nection, etc.
Importing SQLClient won't help in this case... you're using an Access database.
Jeff
Importing SQLClient won't help in this case... you're using an Access database.
Jeff
Also... forgot to add at the end of the code
conn.Close
to close the database connection.
conn.Close
to close the database connection.
Right I forgot his was using access
ASKER
Thanks for the help. It works just as planned.
Mike,
My pleasure. Been doing too much of that stuff lately, so I had the code more or less handy...
Jeff
My pleasure. Been doing too much of that stuff lately, so I had the code more or less handy...
Jeff
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