PDA

View Full Version : Imserting data at runtime in asp.net(VB)


Mistery1
Aug 4, 2009, 12:31 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

shatrughna
Nov 20, 2009, 03:52 AM
Please try using sqldatasource and giving parameter value with ref. control, cookies method u will able to insert records