Moving to a new row!

MarioRammy

Member
Joined
Feb 1, 2008
Messages
12
Programming Experience
Beginner
Hi i've managed to get my VB.net app inserting into the SQL Server Database, the only problem is it only does it once and then does not move to the next roll. The second time i click the button it simply gives me the pop up box but no change to the database happens.





Imports System.Data.SqlClient


Public Class Form1
Inherits System.Windows.Forms.Form
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
'Dim ra As Integer
'integer holds the number of records inserted
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strName11 As String
Dim strName12 As String





strName11 = txt1.Text
strName12 = txt2.text



myConnection = New SqlConnection("Data Source=.server=;db=Database1 ")
myConnection.Open()
myCommand = New SqlCommand("Insert into Table1 (Field1) values ('" & strName11 & "')", myConnection)
myCommand.ExecuteNonQuery()

MessageBox.Show("New Row Inserted") & ra)
strName11 = ""
myConnection.Close()

Me.Hide()
form2.show()
End Sub
End Class




Any idea's?
 
Dump all that code and start afresh, following the advice contained in the DW2 link in my signature.. Read the sction on Creating a Simple Data App first, then wander wherever your curiosity takes you..

I know, you've sweated long and hard over this scrap of code, and youre going to be unwilling to dump it but trust me, you have to, because it's crap. Once you read DW2 you'll be amazed how much easier it will make your data access life, but it will be a learning curve..
 
Back
Top