 |
|
ช่วยทีคับ เขียน code ตัวอย่างให้ดูหน่อยคับ คือ ผมต้องการจะ copy ข้อมูลจากตาราง นึง แล้วส่งข้อมูลไปอีกตาราง นึง |
|
 |
|
|
 |
 |
|
จากที่คุณเขียนก็น่าจะถูกน่ะครับ ส่วนจะ Where อะไรก็เพิ่มเข้าไปครับ
Go to : SQL INSERT ... SELECT
|
 |
 |
 |
 |
Date :
2012-07-09 08:41:23 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click
Dim conn As New OleDbConnection
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Programing\Project_Final\Stores_management_system\Stores_management_system\bin\Database_Access\Database_shop.accdb"
conn.Open()
Try
If Me.txtnamelogin.Text = "" Or Me.txtpwdlogin.Text = "" Then
MsgBox("กรุณากรอกชื่อผู้ใช้งานและรหัสผ่าน", MsgBoxStyle.Exclamation, "Error")
txtnamelogin.Clear()
txtpwdlogin.Clear()
Me.txtnamelogin.Focus()
End If
If txtnamelogin.Text <> "" And txtpwdlogin.Text <> "" Then
Dim cm As New OleDbCommand("select * from login where Username=" & "'" & txtnamelogin.Text & "' and Pwd=" & "'" & txtpwdlogin.Text & "'", conn)
*** Dim insert As String = "INSERT INTO Checkuser (Status,Username,Firstname,Lastname) " & "SELECT (Status,Username,Firstname,Lastname) FROM Login WHERE Status = 'User' "
Dim Rd As OleDbDataReader
Dim User As String
Dim Pass As String
Rd = cm.ExecuteReader
Rd.Read()
User = Rd.Item("Username")
Pass = Rd.Item("Pwd")
If txtnamelogin.Text = User And txtpwdlogin.Text = Pass Then
form_shop.Show()
txtnamelogin.Text = ""
txtpwdlogin.Text = ""
Me.Hide()
End If
conn.Close()
End If
Catch ex As Exception
MsgBox("กรุณากรอกข้อมูลให้ถูกต้อง")
Exit Sub
End Try
End Sub
อธิบายโดยย่อนะคับ เมื่อกดปุ่มLoginโปรแกรมจะรันไปที่หน้าจอForm_Shopและจะส่งข้อมูลของuserไปที่ตารางCheckuserเพื่อบันทึกวันที่login ในส่วนของวันที่loginผมยังไม่ได้ทำเลยคับ
ยังติดปัญหาคัดลอกข้อมูลของตารางอยู่เลยคับ
นีครับช่วนทีนะคับบรรทัดที่ผม *** ไว้คือผมต้องการจะคัดลอกข้อมูลจากตาราง Login ไปตารางCheckuser คือว่าที่ผมเขียนไว้ข้อมูลมันไม่ส่งไปให้อะคับ ต้องประกาศตัวแปรแบบไหนยังไงหรือป่าวคับ
ช่วยอีกทีนะคับพี่ๆ
|
 |
 |
 |
 |
Date :
2012-07-09 16:39:28 |
By :
@por |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมดูแล้วไม่เข้าใจครับ
|
 |
 |
 |
 |
Date :
2012-07-09 22:09:14 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ๋อ .. ผมแก้ได้แล้วคับ ... ขอบคุณพี่มากนะคับที่ช่วยผม
|
 |
 |
 |
 |
Date :
2012-07-10 01:57:23 |
By :
@por |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

|
 |
 |
 |
 |
Date :
2012-07-10 06:19:24 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|