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

        Try
            conn.Open()
            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")
            Else

                usercmd.ExecuteReader()

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

                conn.Close()

            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.

This question has already been answered. Start a new discussion instead.