Think it is an ASP.NET application. I made some changes, marked with XXX. On my system it works. Maybe the changes help you to get your program to work. Databaseprogramming is a wide area.
Imports System
Imports System.data
Imports System.data.sqlclient
'XXX used a standard dataset since I do not have yours Imports dataset1
Public Class WebForm1
Inherits System.Web.UI.Page
'XXX con needs to be in scope when the Insert-Button Click event is handled
Dim con As SqlConnection
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'XXX Dim con As SqlConnection
Dim cmd As SqlCommand
Dim adp As SqlDataAdapter 'XXX use SQLDataAdapter Dim adp As sqladapter
Dim data As DataSet
'XXX I do not have your database, please change connect string as required.
'XXX If you use the SQLClient dataprovider, you do not need the provider keyword.
'XXX instantiated the con object
'con.ConnectionString = "Provider=SQLOLEDB;initialcatalog=preethi;database=ACER;integrated security=true"
con = New SqlConnection
con.ConnectionString = "database=.;initial catalog=contacts;user=ASPNET;"
cmd = New SqlCommand 'XXX instantiated the command object
'XXX connection is assigned below
'cmd.Connection = con
'XXX cmd=new sqlcommand("select * from emp"),con
cmd = New SqlCommand("select * from contacts", con) 'XXX
adp = New SqlDataAdapter(cmd)
data = New DataSet 'instatiated dataset
adp.Fill(data)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
Dim sSQL As String = "INSERT INTO contacts( contactid, firstname, lastname) VALUES (20, 'User20', 'User20Firstname')"
Dim cmd As SqlCommand = New SqlCommand(sSQL, con)
con.Open() 'XXX connection must be opened before command is executed
cmd.ExecuteNonQuery()
con.Close() 'XXX
Response.Write(" One record inserted")
End Sub
End Class
Last edited by dadelsen; Jun 10th, 2008 at 6:28 am.