Hi,
There are lot of sites you can refer to start with. It will be better you have a look in MSDN for ADO and ADO.NET difference. This will help you to make the change over easier. Very nice website to start ADO.NET
http://samples.gotdotnet.com/quickstart/howto/doc/adoplus/ADOPlusOverview.aspx
There are lot of ways you can do an Insert operation in ADO.NET.
I am giving a small piece of code using two different ways to insert a record. The example uses SQL Server's Northwind DB as connection string. You can change to your Database of choice. You can also use ADODB for .NET
Put the following code at the start of your code window. similar place where you put Option explicit declaration in VB 6
Imports System
Imports System.Data
Imports System.Data.OleDb 'This is for OleDb
Imports Microsoft.VisualBasic
Imports System.Data.SqlClient 'This is for SqlClient exclusively for SQL Server DB
Put the following code in any event. Here I am using it in a Button Click Event.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'This is for SQLClient
Dim nwindConn As OleDbConnection = New OleDbConnection("Provider=SQLOLEDB;Data Source=localhost;" & _
"Integrated Security=SSPI;Initial Catalog=northwind")
Dim catCMD As OleDbCommand = nwindConn.CreateCommand()
catCMD.CommandText = "Place your Insert statement"
nwindConn.Open()
catCMD.ExecuteNonQuery()
nwindConn.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'This is for OLEdb
Dim nwindConn As SqlConnection = New SqlConnection("Data Source=localhost;" & _
"Integrated Security=SSPI;Initial Catalog=northwind")
Dim catCMD As SqlCommand = nwindConn.CreateCommand()
catCMD.CommandText = "Place your Insert statement"
nwindConn.Open()
catCMD.ExecuteNonQuery()
nwindConn.Close()
End Sub
Hope this was useful. If you need further help have a look at MSDN. It has some Samples.
Enter your message below
Sign in or Join us (it's free).