S
sudhinma
Hello all,
I created a web form to enter a new record to a access database called
student.mdb.
But when i click the save button(button1) the record does not get
added and i get a exception. the code is in vb and i have used visual
web developer 2005 express edition.the code is as under. IS this the
right way to do it.If not pls suggest a better method.
regards
sudhin
Imports System.Data.OleDb
Partial Class _Default
Inherits System.Web.UI.Page
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
cn = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Visual
Studio 2005\WebSites\WebSite3\App_Data\student.mdb;")
cmd = New OleDbCommand("INSERT INTO student1 (Name,Reg
no,College)VALUES('" & TextBox1.Text & "','" & TextBox2.Text & "','" &
TextBox3.Text & "')", cn)
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
Catch ex As Exception
TextBox1.Text = ex.StackTrace
End Try
End Sub
End Class
I created a web form to enter a new record to a access database called
student.mdb.
But when i click the save button(button1) the record does not get
added and i get a exception. the code is in vb and i have used visual
web developer 2005 express edition.the code is as under. IS this the
right way to do it.If not pls suggest a better method.
regards
sudhin
Imports System.Data.OleDb
Partial Class _Default
Inherits System.Web.UI.Page
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
cn = New
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Visual
Studio 2005\WebSites\WebSite3\App_Data\student.mdb;")
cmd = New OleDbCommand("INSERT INTO student1 (Name,Reg
no,College)VALUES('" & TextBox1.Text & "','" & TextBox2.Text & "','" &
TextBox3.Text & "')", cn)
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
Catch ex As Exception
TextBox1.Text = ex.StackTrace
End Try
End Sub
End Class