Quantcast
Viewing all articles
Browse latest Browse all 27080

VS 2012 Inserting to SQL database from VB App - three rows instead of one.

I am new to VB, and am trying to create a VB app wherby one of the features enables an operator to insert an SQL row.
The below code is working, although, instead of one row being inserted, three rows are being inserted. Any ideas are appreciated. TIA

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

If TextBox1.Text() = "" Or TextBox2.Text = "" Then
MessageBox.Show("Textbox cannot be empty. Please Check")
Else
Try
Dim connectionString As String = "data source=[ip address];initial catalog=Software_Licenses;persist security info=True;user id=id;password=password"
Dim SqlConnection As New SqlConnection(connectionString)
Dim sqlcommand As New SqlCommand("INSERT INTO Software_Licenses.dbo.MasterList (Software,License) VALUES ('" & TextBox1.Text & "','" & TextBox2.Text & "')", SqlConnection)
Dim adapter As New SqlDataAdapter(sqlcommand)
Dim ds As New DataSet("MasterList")
Dim dataTable As New DataTable("MasterList")
ds.Tables.Add("MasterList")
adapter.Fill(ds.Tables.Item("MasterList"))
adapter.Fill(dataTable)
SqlConnection.Open()
sqlcommand.ExecuteNonQuery()
SqlConnection.Close()
Catch ex As Exception

End Try
MessageBox.Show("You have successfully updated the License Master List", "Success")
Close()

End If
End Sub

Viewing all articles
Browse latest Browse all 27080

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>