Hi guys!

I created a simple code to add records into an SQL database as shown below. It seemed to be working but then the next time i tried running it, i got no output. actually on clicking the button nothing happens at all. no warnings or error messages at all.

Here's the code:

Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click

            userstring = ("select UserID from dbo.Users")

            userstring = ("insert into dbo.Users (UserID,UserName,Password) values ('" & txtuserid.Text & "','" & txtusername.Text & "','" & txtpassword.Text & "')")
            usercmd = New SqlCommand(userstring, conn)

            If txtuserid.Text = "" Or txtusername.Text = "" Or txtpassword.Text = "" Then
                MsgBox("Missing details. Please review", MsgBoxStyle.Exclamation, "Warning")


                MsgBox("User successfully added!", MsgBoxStyle.Information)


            End If

        Catch ex As Exception
            'MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OkOnly, "Connection Error !!")
            If ex.Message.Substring(0, 9) = "Violation" Then
                MsgBox("User ID already exists. Try again")
            End If
        End Try
    End Sub

If someone can see anything wrong with this code please point it out. Thank you.

This is strange. The code looks fine. Did you have a look at your database? Does it save the data into a new recordset, even though nothing seems to happen?

its ok. i figured out what it was - there was a header (import statement) that was missing. anyway its all good now.

Cool man. Please close this thread for us please. I see you have another one also still open with the connection to sql. Please close this as well, thanks.:)

This is the link to the other post -http://www.daniweb.com/forums/thread318164.html

Happy coding.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.