PDA

View Full Version : Inserting data into a database using asp.net(visual Basic)


Mistery1
Jul 30, 2009, 07:51 AM
Hi there,


Protected Sub ButtonSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonSubmit.Click


Dim cn As New OleDbConnection
Dim str As String
Dim cmd As New OleDbCommand

cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Mistery1\Desktop\Emp.mdb;")
cn.Open()


Str = "INSERT INTO EmpNames(EmpNo, Ename, Department) VALUES(" & CInt(TextBoxEmpNo.Text) & ",'" & TextBoxEname.Text.Replace("'", "''") & "','" & TextBoxDepartment.Text.Replace("'", "''") & "')"

cmd = New OleDbCommand(Str, cn)
str = cmd.ExecuteNonQuery

cn.Close()

End sub



I am trying to create a website using ASP.net 2.0 and VB(not c#). The code above works perfectly when used as a windows application but not as a web application.

Please could someone tell me where I'm going wrong. I don't get any errors, just NO entry in the database. I have googled but to no avail.

Please help