ian using visual studio 2005 to gesign my asp pages and i have aa access database to hold few important information
the problem is iam not able to connect to it to upload new valuse
its like i have a forum from which i get the new entries from the customers and upload it to the data base
my code is like this
Imports System.Data.OleDb
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; DataSource=MyDB.mdb;")
Dim da As New OleDbDataAdapter("select * from emp", cn)
Dim dt As New Data.DataTable
da.Fill(dt)
da.Dispose()
cn.Dispose()
Me.GridView1.DataSource = dt
Me.GridView1.DataBind()
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; DataSource=MyDB.mdb;")
Dim cmd As New OleDbCommand
With cmd
.CommandText = "insert into emp (Empno,Ename,Sal,Deptno) values (" & Me.TextBox1.Text & ",'" & Me.TextBox2.Text & "'," & Me.TextBox3.Text & "," & Me.TextBox4.Text & ")"
.Connection = cn
.Connection.Open()
.ExecuteNonQuery()
.Connection.Close()
.Dispose()
End With
cn.Dispose()
'refresh the list
'btnList_Click(Nothing, Nothing)
End Sub
End Class
the button one is used to add the entered datas into the data base
and the second button to view the updated databse