inserting into db not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • slider
    New Member
    • Feb 2007
    • 27

    #1

    inserting into db not working

    hey all..i am using sql server 2000 and writing my code in asp.net in visual basic language.
    the code i am using to connect to the database is

    [CODE]Dim strConn As String = "Data Source=myserver t;Initial Catalog=mydb;Us erId=username"
    Dim cmd As New SqlCommand("INS ERT into Pictures (USER_ID) values ('" & userID & "')", New SqlConnection(s trConn))
    cmd.Connection. Open()
    cmd.ExecuteNonQ uery()
    cmd.Connection. Close()
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    Try passing the userID without putting them inside quote marks.. like:
    [code=sql]
    INSERT INTO tbl(ID) VALUES(1);
    /* And not */
    INSERT INTO tbl(ID) VALUES('1');
    [/code]

    Comment

    • slider
      New Member
      • Feb 2007
      • 27

      #3
      hey there thanks but nah that didnt work.
      i believe that the query isnt getting executed for some reason

      Comment

      • slider
        New Member
        • Feb 2007
        • 27

        #4
        ok i have solved the problem..someth ing so simple!


        This line here works perfectly in asp but in asp.net the userid=username needed to be
        Code:
        <%Dim strConn As String = "Data Source=myservert;Initial Catalog=mydb;User Id=username"%>
        just adding the space fixed it :D

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Originally posted by slider
          ok i have solved the problem..someth ing so simple!


          This line here works perfectly in asp but in asp.net the userid=username needed to be
          Code:
          <%Dim strConn As String = "Data Source=myservert;Initial Catalog=mydb;User Id=username"%>
          just adding the space fixed it :D
          Ahh I see. It's always so easy to overlook the simple things :)

          Glad you got it fixed.

          Comment

          Working...