Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.OleDb
Public Class Form1
Private Sub login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles login.Click
Dim dtAdapter As SqlDataAdapter
Dim objConn As SqlConnection
Dim dt As New DataTable
Dim strConnString As String
strConnString = "Server=ZEROYAKI;Uid=sa;PASSWORD=1234;database=user;"
objConn = New SqlConnection(strConnString)
objConn.Open()
Dim strSQL As String
strSQL = "SELECT * FROM tbl_user WHERE username = '" & Me.TextBox1.Text & "'" & _
" AND password = '" & Me.TextBox2.Text & "'" & _
" AND user_id = '" & Me.TextBox3.Text & "'"
dtAdapter = New SqlDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
If dt.Rows.Count <= 0 Then
MessageBox.Show("Invalid Username & Password")
Else
'TODO: This line of code loads data into the 'UserDataSet.tbl_user' table. You can move, or remove it, as needed.
Me.Tbl_userTableAdapter.Fill(Me.UserDataSet.tbl_user)
End If
End Sub
Private Sub add_data_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles add_data.Click
Dim objConn As New SqlConnection
Dim objCmd As New SqlCommand
Dim dtAdapter As SqlDataAdapter
Dim dt As New DataTable
Dim strConnString, strSQL, strSQLinsert, strConnStringinsert As String
strConnString = "Server=ZEROYAKI;Uid=sa;PASSWORD=1234;database=user;"
objConn.ConnectionString = strConnString
objConn.Open()
strSQL = "SELECT * FROM tbl_user WHERE username = '" & Me.TextBox1.Text & "'" & _
" AND password = '" & Me.TextBox2.Text & "'" & _
" AND user_id = '" & Me.TextBox3.Text & "'"
dtAdapter = New SqlDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
If dt.Rows.Count > 0 Then
MessageBox.Show("มีข้อมูลชื่อผู้ใช้นี้แล้ว กรุณาเพิ่มชื่อผู้ใช้ใหม่")
Else
Dim objConn2 As New SqlConnection
Dim objCmd2 As New SqlCommand
strConnStringinsert = "Server=ZEROYAKI;Uid=sa;PASSWORD=1234;database=user;"
objConn2.ConnectionString = strConnStringinsert
objConn2.Open()
strSQLinsert = "INSERT INTO tbl_user " & _
" VALUES ('" & Me.TextBox3.Text & "','" & Me.TextBox1.Text & "','" & Me.TextBox2.Text & "')"
dtAdapter = New SqlDataAdapter(strSQLinsert, objConn2)
dtAdapter.Fill(dt)
With objCmd2
.Connection = objConn2
.CommandText = strSQLinsert
.CommandType = CommandType.Text
End With
objConn2.Close()
objConn2 = Nothing
MessageBox.Show("เพิ่มข้อมูลชื่อผู้ใช้เรียบร้อย")
End If
End Sub
Private Sub Tbl_userBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tbl_userBindingNavigatorSaveItem.Click
Me.Validate()
Me.Tbl_userBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.UserDataSet)
End Sub
Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
End Sub
End Class
Tag : .NET, Ms SQL Server 2005, VB.NET, VS 2010 (.NET 4.x)
Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
End Sub
Private Sub Tbl_userBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tbl_userBindingNavigatorSaveItem.Click
Me.Validate()
Me.Tbl_userBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.UserDataSet)
End Sub
Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
End Sub