|
|
|
VB6 คำสั่งเขียนเช็คข้อมูลซ้ำในวีบีหก เราต้องเขียนยังไงคับ |
|
|
|
|
|
|
|
Code (VB.NET)
Private Sub Add_Proj_Click()
On Error GoTo ErrorHandler
If Proj_code.Text = "" Then
MsgBox "¡ÃسҡÃÍ¡¢éÍÁÙÅ Project Code ´éǤÃѺ"
Proj_code.SetFocus
ElseIf Cus_code_proj.Text = "" Then
MsgBox "¡ÃسҡÃÍ¡¢éÍÁÙÅ Customer Code´éǤÃѺ"
Cus_code_proj.SetFocus
ElseIf Proj_name.Text = "" Then
MsgBox "¡ÃسҡÃÍ¡¢éÍÁÙÅ Project Name ´éǤÃѺ"
Proj_name.SetFocus
ElseIf CP_name.Text = "" Then
MsgBox "¡ÃسҡÃÍ¡¢éÍÁÙÅ CP Name ´éǤÃѺ"
CP_name.SetFocus
ElseIf CP_Team.Text = "" Then
MsgBox "¡ÃسҡÃÍ¡¢éÍÁÙÅ CP Team ´éǤÃѺ"
CP_Team.SetFocus
ElseIf SM_name.Text = "" Then
MsgBox "¡ÃسҡÃÍ¡¢éÍÁÙÅ SM Name ´éǤÃѺ"
SM_name.SetFocus
ElseIf PS_name.Text = "" Then
MsgBox "¡ÃسҡÃÍ¡¢éÍÁÙÅ PS Name ´éǤÃѺ"
PS_name.SetFocus
ElseIf OPP_txt.Text = "" Then
MsgBox "¡ÃسҡÃÍ¡¢éÍÁÙÅ OPP ´éǤÃѺ"
OPP_txt.SetFocus
ElseIf Start_date.Text = "" Then
MsgBox "¡ÃسҡÃÍ¡¢éÍÁÙÅ Start Sale Date ´éǤÃѺ"
Start_date.SetFocus
ElseIf Close_date.Text = "" Then
MsgBox "¡ÃسҡÃÍ¡¢éÍÁÙÅ Close sale Date ´éǤÃѺ"
Close_date.SetFocus
ElseIf User_date.Text = "" Then
MsgBox "¡ÃسҡÃÍ¡¢éÍÁÙÅ User Date ´éǤÃѺ"
User_date.SetFocus
ElseIf User_ID.Text = "" Then
MsgBox "¡ÃسҡÃÍ¡¢éÍÁÙÅ User ID ´éǤÃѺ"
User_ID.SetFocus
Else
Dim sqlStr As String
Dim conn As New ADODB.Connection
Dim sqlCm As New ADODB.Command
Dim rs As New ADODB.Recordset
sqlStr = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;Port=3307;Database=vb_project;Uid=root;Pwd=admin;"
conn.ConnectionString = sqlStr
conn.Open
Dim Statement As String
Statement = "INSERT INTO project" & _
"(PROJECT_CODE,CUSTOMER_CODE,PROJECT_NAME,CP_NAME,CP_TEAM,SM_NAME,PS_NAME,OPP,START_SALE_DATE," & _
"CLOSE_SALE_DATE,SW_COST,SW_GP,HW_COST,HW_GP,PS_COST,PS_GP,TOTAL_COST,TOTAL_GP,USER_DATE,USER_ID) " & _
" VALUES (" & _
"'" & Proj_code.Text & "', " & _
"'" & Cus_code_proj.Text & "', " & _
"'" & Proj_name.Text & "', " & _
"'" & CP_name.Text & "'," & _
"'" & CP_Team.Text & "'," & _
"'" & SM_name.Text & "'," & _
"'" & PS_name.Text & "'," & _
"'" & OPP_txt.Text & "'," & _
"'" & Start_date.Text & "'," & _
"'" & Close_date.Text & "'," & _
"'" & SW_cost.Text & "'," & _
"'" & SW_GP.Text & "'," & _
"'" & HW_cost.Text & "'," & _
"'" & HW_GP.Text & "'," & _
"'" & PS_cost.Text & "'," & _
"'" & PS_GP.Text & "'," & _
"'" & Total_Cost.Text & "'," & _
"'" & Total_GP.Text & "'," & _
"'" & User_date.Text & "'," & _
"'" & User_ID.Text & "'" & _
")"
conn.Execute Statement, , adCmdText
conn.Close
MsgBox "Add Done", vbOKOnly, "Done"
Proj_code.Text = ""
Cus_code_proj.Text = ""
Proj_name.Text = ""
CP_name.Text = ""
CP_Team.Text = ""
SM_name.Text = ""
PS_name.Text = ""
OPP_txt.Text = ""
Start_date.Text = ""
Close_date.Text = ""
SW_cost.Text = ""
SW_GP.Text = ""
HW_cost.Text = ""
HW_GP.Text = ""
PS_cost.Text = ""
PS_GP.Text = ""
Total_Cost.Text = ""
Total_GP.Text = ""
User_date.Text = ""
User_ID.Text = ""
Call ConnToDB2
DataGrid1.Refresh
Exit Sub
End If
ErrorHandler: MsgBox Err.Description, , "Error"
End Sub
Tag : MySQL, VB.NET
|
|
|
|
|
|
Date :
2011-12-14 14:53:03 |
By :
เด็กกระทิง |
View :
1733 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เหมือนบทความ ASP เลยครับ ไม่ต่างกัน
Code (ASP)
<%
Dim Conn,strSQL,objRec,objExec
Set Conn = Server.Createobject("ADODB.Connection")
Conn.Open "DRIVER={MySQL ODBC 5.1 Driver}; SERVER=localhost;UID=root; " & _
"pwd=root;database=mydatabase;option=16384;"
strSQL = "SELECT * FROM customer WHERE CustomerID = '"&Request.Form("txtCustomerID")&"' "
Set objRec = Conn.Execute(strSQL)
IF Not objRec.EOF Then
Response.write("CustomerID already exist.")
Else
strSQL = ""
strSQL = strSQL &"INSERT INTO customer "
strSQL = strSQL &"(CustomerID,Name,Email,CountryCode,Budget,Used) "
strSQL = strSQL &"VALUES "
strSQL = strSQL &"('"&Request.Form("txtCustomerID")&"','"&Request.Form("txtName")&"', '"&Request.Form("txtEmail")&"' "
strSQL = strSQL &",'"&Request.Form("txtCountryCode")&"','"&Request.Form("txtBudget")&"', '"&Request.Form("txtUsed")&"') "
Set objExec = Conn.Execute(strSQL)
If Err.Number = 0 Then
Response.write("Save Done.")
Else
Response.write("Error Save ["&strSQL&"]")
End If
Set objExec = Nothing
End If
objRec.Close
Conn.Close()
Set objRec = Nothing
Set Conn = Nothing
%>
|
|
|
|
|
Date :
2011-12-14 18:03:01 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|