i have problem insert record in database

asp.net , xhtml Adelaide, Australia
  • 12 years ago

    <%@ Page Language="VB" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.OLEDB" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

       
     
        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim con As New System.Data.OleDb.OleDbConnection
            Dim myPath As String
            myPath = Server.MapPath("nwind.mdb")
            con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=" & myPath & ";"
            Dim myCommand As New System.Data.OleDb.OleDbCommand()
            myCommand.CommandText = "INSERT INTO login(username,password)values('" & txtUsername.Text & "','" & txtPassword.Text & "')"
            myCommand.Connection = con
            con.Open()
            myCommand.ExecuteNonQuery()
            con.Close()
        End Sub
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>

    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            username
            <asp:TextBox ID="txtUsername" runat="server" ></asp:TextBox>
            <br />
            <br />
            password<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox><br />
            <br />
           
            <asp:Button ID="btnsubmit" runat="server" OnClick="Button1_Click" Text="Button" /></div>
        </form>
    </body>
    </html>
    i have problem at

    myCommand.ExecutionNonQuery()

     

    Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement.
     

  • 12 years ago

    sorry parakash for late response man em using ur trick but i have found again same error...!

     

    kindly tell me whatz de problem em in big trouble...!

     

    <%@ Page Language="VB" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.OLEDB" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

      
     
        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            Dim con As New System.Data.OleDb.OleDbConnection
            Dim myPath As String
            myPath = Server.MapPath("nwind.mdb")
            con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data source=" & myPath & ";"
            Dim myCommand As New System.Data.OleDb.OleDbCommand()
            myCommand.CommandText = "INSERT INTO login(username,password)values('" + txtUsername.Text + "','" + txtPassword.Text + "')"
            myCommand.Connection = con
            con.Open()
            myCommand.ExecuteNonQuery()
            con.Close()
        End Sub
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>Untitled Page</title>

    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            username
            <asp:TextBox ID="txtUsername" runat="server" ></asp:TextBox>
            <br />
            <br />
            password<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox><br />
            <br />
          
            <asp:Button ID="btnsubmit" runat="server" OnClick="Button1_Click" Text="Button" /></div>
        </form>
    </body>
    </html>

  • 12 years ago

    can u post your exception ... where  we can find the exact problem


     

  • 12 years ago
    my problem has been solved . thankz for supporting

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity.” - Dennis Ritchie