Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports System.Linq
Imports System.Text
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Drawing.Image
Imports System.Windows.Forms
Imports System.Drawing.Printing
Imports System.Reflection
Public Class frmCustomer
Private webcam As Webcam
Private ClassProcessDateAGE As ProcessDate
Public locationPhoto, locationPhotoEducation As String
Public Conn As SqlConnection
Public com As SqlCommand
Public strConn As String
Public tr As SqlTransaction
Public sb As New StringBuilder()
Public bs As New BindingSource()
Public IsFind As Boolean = False
Dim strSQL2 As String
Dim num As Integer
'SET MEMBER
Public tb_Name As String = "tbCustomer"
Public fieldId As String = "CustomerID"
Public field1 As String = "NameCategoryRental"
Public field2 As String = "SexName"
Public field3 As String = "AheadName"
Public field4 As String = "FLName"
Public field5 As String = "CardID"
Public field6 As String = "BirthDate"
Public field7 As String = "Address"
Public field8 As String = "Telephone"
Public th As String = "ลูกค้า"
'SET TYPE
Public tb_NameAhead As String = "tbAheadName"
Public fieldIdAhead As String = "AheadNameID"
Public field1Ahead As String = "AheadName"
Public tb_NameSex As String = "tbSex"
Public fieldIdSex As String = "SexID"
Public field1Sex As String = "SexName"
Public tb_NameCategoryR As String = "tbCategoryRental"
Public fieldIdCategoryR As String = "CategoryRentalID"
Public field1CategoryR As String = "NameCategoryRental"
'
Dim da, da2, da3, da4, da5, da6, da7, da8, da9, da10, da11 As SqlDataAdapter
Dim ds, ds2, ds3, ds4, ds5, ds6, ds7, ds8, ds9, ds10, ds11 As New DataSet()
Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
ReadConnectSQLServer()
If txtCustomerID.Text.Trim() = "" Then
MessageBox.Show("กรุณาป้อนเลขที่" & th & "ก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtCustomerID.Focus()
Exit Sub
End If
If txtFirstName.Text.Trim() = "" Then
MessageBox.Show("กรุณาป้อนชื่อ" & th & "ก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtFirstName.Focus()
Exit Sub
End If
If txtCardID.Text.Trim() = "" Then
MessageBox.Show("กรุณาป้อนเลขบัตรประชาชน" & th & "ก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
txtCardID.Focus()
Exit Sub
End If
If MessageBox.Show("คุณต้องการเพิ่ม" & th & "ใหม่ ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Dim strSQL, strSQL2, strSQL3 As String
Dim intNumRow, intNumRow2, intNumRow3 As Integer
strSQL = "SELECT COUNT(*) FROM " & tb_Name & " WHERE " & fieldId & " = '" & txtCustomerID.Text & "' "
Dim objCmd, objCmd2, objCmd3, objCmd4, objCmd5, objCmd6 As New SqlCommand
objCmd = New SqlCommand(strSQL, Conn)
intNumRow = objCmd.ExecuteScalar()
strSQL2 = "SELECT COUNT(*) FROM " & tb_Name & " WHERE " & field4 & " = '" & txtFirstName.Text & "' "
objCmd2 = New SqlCommand(strSQL2, Conn)
intNumRow2 = objCmd2.ExecuteScalar()
strSQL3 = "SELECT COUNT(*) FROM " & tb_Name & " WHERE " & field5 & " = '" & txtCardID.Text & "' "
objCmd3 = New SqlCommand(strSQL2, Conn)
intNumRow3 = objCmd2.ExecuteScalar()
If intNumRow3 > 0 Then
MessageBox.Show("เลขบัตรประชนซ้ำ!!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If intNumRow2 > 0 Then
MessageBox.Show("ชื่อซ้ำ!!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
If intNumRow > 0 Then
MessageBox.Show("เลขที่ลูกค้าซ้ำ!!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
Else
Dim com As New SqlCommand("INSERT INTO " & tb_Name & "(" & fieldId & "," & field1 & "," & field2 & "," & field3 & "," & field4 & "," & field5 & "," & field6 & "," & field7 & "," & field8 & ") VALUES('" & txtCustomerID.Text.ToString & "','" & cbCateRental.SelectedValue.ToString & "','" & cbSex.SelectedValue.ToString & "','" & cbAheadName.SelectedValue.ToString & "','" & txtFirstName.Text.ToString & "','" & txtCardID.Text.ToString & "','" & DateTimePicker1.Text.ToString & "','" & txtAddress.Text.ToString & "','" & txtTelephone.Text.ToString & "')", Conn)
com.ExecuteReader()
ShowData()
Format()
MessageBox.Show("ทำการบันทึกเรียบร้อย!!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End If
txtFirstName.Focus()
End Sub
ดาต้าเบสของผมเป็นvarcharทั้งหมดอ่าครับ
Tag : .NET, Ms SQL Server 2008, Win (Windows App), VB.NET, VS 2010 (.NET 4.x)