insert data with vb

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • idsanjeev
    New Member
    • Oct 2007
    • 241

    #1

    insert data with vb

    this code repred error
    ERROR [42000] [Microsoft][ODBC driver for Oracle][Oracle]ORA-00936: missing expression
    Code:
    <%@ Page Language="VB" %>
    <%@ import Namespace="System.Data.ODbc" %>
    <%@ import Namespace=" System.Data" %>
    <script runat="server">
    
        Sub submit(sender As Object, e As EventArgs)
           ' lbl.text= "hello" &id.text
    		'txt.text= "hello" &id.text
         dim dbconn
         dbconn=New ODbcConnection("dsn=oracle;uid=starter;pwd=starter;")
        dbconn.Open()
            dim isql,idbread,idbcomm
            isql="Insert Into students(id,first_name,last_name,major) values (@fname,@id,@lname,@major)"
            idbcomm=new odbccommand(isql,dbconn)
            idbcomm.Parameters.Add( "@fname",fname.text)
         idbcomm.Parameters.Add( "@id",id.Text)
         idbcomm.Parameters.Add( "@lname",lname.Text)
         idbcomm.Parameters.Add( "@major",major.Text)
         idbcomm.ExecuteNonQuery()
         dbconn.Close()
         End Sub
    
    </script>
    <html>
    <head>
    </head>
    <body>
        <form runat="server">
            <th>Id Number:</th>
            <asp:TextBox id="id" runat="server"></asp:TextBox>
            <br />
            <br />
            <th>MaJor:</th>
            <asp:TextBox id="major" runat="server"></asp:TextBox>
            <br />
            <br />
            <th>First Name:</th>
            <asp:TextBox id="fname" runat="server"></asp:TextBox>
            <br />
            <br />
            <th>Last Name:</th>
            <asp:TextBox id="lname" runat="server"></asp:TextBox>
            <br />
            <asp:Label id="lbl" runat="server" text="Label" width="80px"></asp:Label>
            <br />
    		        <br />
            <th>Last Name:</th>
            <asp:TextBox id="txt" runat="server"></asp:TextBox>
            <br />
            <hr />
            <asp:Button id="Button1" onclick="submit" runat="server" Text="Submit"></asp:Button>
        </form>
    </body>
    </html>
  • jimmoon
    New Member
    • Jun 2008
    • 2

    #2
    Line 13 looks odd, fname is being inserted into the ID field.

    Comment

    • idsanjeev
      New Member
      • Oct 2007
      • 241

      #3
      Originally posted by jimmoon
      Line 13 looks odd, fname is being inserted into the ID field.
      thanks
      i try to change that like after creating new table
      Code:
          dbconn.Open()
              dim isql,idbread,idbcomm
              isql="Insert Into stud(id,firstname,lastname,major) values (@id,@fname,@lname,@major)"
              idbcomm=new odbccommand(isql,dbconn)
              idbcomm.Parameters.Add( "@id",id.Text)        
      		idbcomm.Parameters.Add( "@fname",fname.text)
              idbcomm.Parameters.Add( "@lname",lname.Text)
              idbcomm.Parameters.Add( "@major",major.Text)
              idbcomm.ExecuteNonQuery()
              dbconn.Close()
           End Sub

      Comment

      • idsanjeev
        New Member
        • Oct 2007
        • 241

        #4
        now i am strugling with same error

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          Originally posted by idsanjeev
          thanks
          i try to change that like after creating new table
          Code:
              dbconn.Open()
                  dim isql,idbread,idbcomm
                  isql="Insert Into stud(id,firstname,lastname,major) values (@id,@fname,@lname,@major)"
                  idbcomm=new odbccommand(isql,dbconn)
                  idbcomm.Parameters.Add( "@id",id.Text)        
          		idbcomm.Parameters.Add( "@fname",fname.text)
                  idbcomm.Parameters.Add( "@lname",lname.Text)
                  idbcomm.Parameters.Add( "@major",major.Text)
                  idbcomm.ExecuteNonQuery()
                  dbconn.Close()
               End Sub
          The error you've specified indicates that you're missing a part of your SQL command. Looking at your Insert Into statement, everything looks okay...so long as there is a table named "stud".


          Try putting in spaces after your commas in your command:

          isql="Insert Into stud(id, firstname, lastname, major) values (@id, @fname, @lname, @major)"


          Does your stud table only have columns: id, firstname,lastn ame,major? Or does it contain others?

          -Frinny

          Comment

          • idsanjeev
            New Member
            • Oct 2007
            • 241

            #6
            the tbales creation scripts is
            CREATE TABLE STUD
            (
            ID VARCHAR2(5),
            FIRSTNAME VARCHAR2(20),
            LASTNAME VARCHAR2(10),
            MAJOR VARCHAR2(10)
            )

            so no any other fields in it also try to putting space but getting same error

            Comment

            • DrBunchman
              Recognized Expert Contributor
              • Jan 2008
              • 979

              #7
              Does the sql work if you run it against the database in a query analyser?

              Have you tried removing the parameters and using the value of your controls in the string directly? e.g.
              Code:
               
              values ('" & id.Text & "', '" & fname.text & "', etc
              Are you certain that all your controls contain a value at this point?

              Dr B

              Comment

              • idsanjeev
                New Member
                • Oct 2007
                • 241

                #8
                Originally posted by DrBunchman
                Code:
                 
                values ('" & id.Text & "', '" & fname.text & "', etc
                Are you certain that all your controls contain a value at this point?
                Dr B
                hello Dr B
                this code is working fine
                Code:
                 
                values ('" & id.Text & "', '" & fname.text & "', etc
                but i wnats ot know whats are the porblems in my code with
                Code:
                idbcomm.Parameters.Add( "@id",id.Text)
                Regards
                jha

                Comment

                • idsanjeev
                  New Member
                  • Oct 2007
                  • 241

                  #9
                  the modified code is worked
                  Code:
                          isql="Insert Into stud(id, firstname, lastname, major) values (?, ?, ?, ?)"
                          idbcomm=new odbccommand(isql,dbconn)
                          idbcomm.Parameters.Add("id", id.Text)       
                          idbcomm.Parameters.Add("fname", fname.text)
                          idbcomm.Parameters.Add("lname", lname.Text)
                          idbcomm.Parameters.Add("major", major.Text) 
                          idbcomm.ExecuteNonQuery()
                  i think @ is not worked with odbc .
                  I am not sure .
                  if any idea?
                  Regards
                  jha

                  Comment

                  Working...