Insert + SQLexpress + Add User










Imports System.Data.SqlClient
Public Class Form1
    Dim myConnection As SqlConnection
    Dim myCommand As SqlCommand
    Dim ra As Integer
    Dim sql As String
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.TbthaiTableAdapter.Fill(Me.DataSet1.tbthai)
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Close()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' http://www.startvbdotnet.com/ado/sqlserver1.aspx (structure code)
        ' http://www.eggheadcafe.com/articles/20040703.asp (connection)
        ' myConnection = New SqlConnection("server=.\sqlexpress;Integrated Security=True;database=dbthai")
        myConnection = New SqlConnection("server=.\sqlexpress;" + _
                       "user id=thai;password=thai2007;database=dbthai")
        myConnection.Open()
        sql = "insert into tbthai values ("
        sql = sql + TextBox1.Text + ","
        sql = sql + "'" + TextBox2.Text + "')"
        myCommand = New SqlCommand(sql, myConnection)
        ra = myCommand.ExecuteNonQuery()
        MessageBox.Show("New Row Inserted " & ra)
        myConnection.Close()
        Me.TbthaiTableAdapter.Fill(Me.DataSet1.tbthai)
    End Sub
End Class

http://goo.gl/72BPC