-
Nov 18th, 2013, 01:49 AM
#1
Thread Starter
New Member
[RESOLVED] 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
-
Nov 18th, 2013, 06:43 AM
#2
Re: Inserting to SQL database from VB App - three rows instead of one.
All three of these are adding rows:
ds.Tables.Add("MasterList")
adapter.Fill(ds.Tables.Item("MasterList"))
adapter.Fill(dataTable)
SqlConnection.Open()
Take your pick and keep one
-
Nov 18th, 2013, 06:52 AM
#3
Thread Starter
New Member
Re: Inserting to SQL database from VB App - three rows instead of one.
Originally Posted by TysonLPrice
All three of these are adding rows:
ds.Tables.Add("MasterList")
adapter.Fill(ds.Tables.Item("MasterList"))
adapter.Fill(dataTable)
SqlConnection.Open()
Take your pick and keep one
Thank you very much... you are the man!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|