and i want to add button used to save the database from VB to SQL
but i have Error in this code and i dont know where
Public Class Form1
Dim cnn As New SqlClient.SqlConnection
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.EMPTableAdapter.Fill(Me.TestDataSet.EMP)
cnn = New SqlClient.SqlConnection
cnn.ConnectionString = "Data Source=" & Application.StartupPath & "\--\sql2005;Initial Catalog=Test1;Integrated Security=True"
End Sub
Private Sub RefreshData()
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
Dim da As New SqlClient.SqlDataAdapter("SELECT ID," & _
" Name, Age, Gender" & _
" FROM EMP ORDER BY ID ", cnn)
da.Fill(TestDataSet.EMP)
cnn.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cmd As New SqlClient.SqlCommand
If Not cnn.State = ConnectionState.Open Then
cnn.Open()
End If
cmd.Connection = cnn
cmd.CommandText = " INSERT INTO Form1 (ID, Name, Age, Gender )" & _
"VALUES (" & Me.TextBox1.Text & "," & Me.TextBox2.Text & "," & Me.TextBox3.Text & "," & _
Me.ComboBox1.Text & ")"
cmd.ExecuteNonQuery()
RefreshData()
cnn.Close()
End Sub
End Class

New Topic/Question
Reply



MultiQuote





|