Results 1 to 4 of 4

Thread: Why wont this work!??!??!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Toronto, Ontario, Canada
    Posts
    275

    Why wont this work!??!??!

    Hey,

    I am a 13 year old developer. I was playing around with SQL Server 2k0 Eval. Edition. Can someone tell me why this wont work?

    VB Code:
    1. Dim stringa, stringb As String
    2.         stringa = Server.HtmlEncode(TextBox1.Text)
    3.         stringb = Server.HtmlEncode(TextBox2.Text)
    4.         Dim cmd As SqlCommand
    5.         Dim cnn As SqlConnection
    6.         cnn = New SqlConnection("server=localhost;user=dex2;pwd=password1;database=pocketdotnet;")
    7.         cmd = New SqlCommand("INSERT INTO " & Me.Session.Item("workgroup") & "News (title, disc, postedby, uid) VALUES ('" & stringa & "', '" & stringb & "', '" & Me.Session.Item("username") & "', '" & Int((999999 - 11111 + 1) * Rnd() + 11111) & "'", cnn)
    8.         cnn.Open()
    9.         cmd.ExecuteNonQuery()
    10.         cnn.Close()

    Thanks!

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Are you getting any errors??

    Also you might wanna try using parameters for your sql statement.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Toronto, Ontario, Canada
    Posts
    275
    there is my error..btw i don't think this makes a diff. but I am using .NET Framework version 1.2 Alpha...here is the what i get...
    Attached Images Attached Images  

  4. #4
    Addicted Member Buy2easy.com's Avatar
    Join Date
    Jul 2002
    Posts
    200
    Try entering in the connection and sql statement manually...it has been a while since i have done it (i wrote a library to do DB stuff) but i think there is a cmd.connection variable and a cmd.command or something like that also double check to make sure that you have all you column names correct cause if not then it will throw an error...also use the database connection toolbox to create a connection to your DB and then go to the connection properties to get the connection string that it creates. I will try to post back later with the code I used to perform an executenonquery.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width