Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   ASP (https://www.askmehelpdesk.com/forumdisplay.php?f=451)
-   -   Imserting data at runtime in asp.net(VB) (https://www.askmehelpdesk.com/showthread.php?t=383216)

  • Aug 4, 2009, 12:31 AM
    Mistery1
    Imserting data at runtime in asp.net(VB)
    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
  • Nov 20, 2009, 03:52 AM
    shatrughna

    Please try using sqldatasource and giving parameter value with ref. control, cookies method u will able to insert records

  • All times are GMT -7. The time now is 11:47 AM.