|
 |
|
ถามเรื่องการบันทึกลง 2 ตารางพร้อมกันหน่อยครับ มีโค้ดให้ช่วยดูหน่อยครับ |
|
 |
|
|
 |
 |
|
ผมอยากบันทึกลง 2 ตารางพร้อมกันอ่ะครับ เลยลองใช้ คำ สั่ง SQL 2 ครั้งดู แต่ผมออกมาเป็น มันบันทึกแค่ตารางเดียวคือตาราง backdata ที่เป็นคำสั่งการบันทึกลงตารางที่ 2 แต่ตารางที่ 1 มันไม่บันทึก ควรเขียนใหม่ยังไงดีครับ
Code (VB.NET)
Dim objConn As SqlCeConnection
objConn = New SqlCeConnection("Data source=D:\Project New test\WindowsApplication1\WindowsApplication1\Database1.sdf;")
objConn.Open()
Dim objCmd As New SqlCeCommand
Dim strSQL As String
Dim intnumrows As Integer
strSQL = "SELECT COUNT(*) FROM saveteble where computer = '" & Me.txtcomputer.Text & "' "
objCmd = New SqlCeCommand(strSQL, objConn)
intnumrows = objCmd.ExecuteScalar
If intnumrows > 0 Then
MessageBox.Show("คอมพิวเตอร์เครื่องนี้มีคนเลือกแล้ว")
Else
strSQL = "insert into [saveTeble] ([id],[name],[surname],[department],[Number],[year],[time],[computer]) values " & _
" ('" & Me.lblUser.Text & "','" & Me.lblName.Text & "','" & Me.lblsurName.Text & "','" & Me.lbldm.Text & "','" & Me.lblnumber.Text & "','" & Me.lblyear.Text & "','" & Now & "','" & Me.txtcomputer.Text & "')"
strSQL = "insert into [backdata] ([id],[name],[surname],[department],[Number],[year],[time],[computer]) values " & _
" ('" & Me.lblUser.Text & "','" & Me.lblName.Text & "','" & Me.lblsurName.Text & "','" & Me.lbldm.Text & "','" & Me.lblnumber.Text & "','" & Me.lblyear.Text & "','" & Now & "','" & Me.txtcomputer.Text & "')"
objCmd = New SqlCeCommand
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
Tag : .NET, VB.NET

|
|
 |
 |
 |
 |
Date :
2012-03-08 22:13:48 |
By :
Mikkola |
View :
1204 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คุณก็เขียน 2 ชุดครับ
Code (VB.NET)
strSQL = "insert into [saveTeble] ([id],[name],[surname],[department],[Number],[year],[time],[computer]) values " & _
" ('" & Me.lblUser.Text & "','" & Me.lblName.Text & "','" & Me.lblsurName.Text & "','" & Me.lbldm.Text & "','" & Me.lblnumber.Text & "','" & Me.lblyear.Text & "','" & Now & "','" & Me.txtcomputer.Text & "')"
objCmd = New SqlCeCommand
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
strSQL = "insert into [backdata] ([id],[name],[surname],[department],[Number],[year],[time],[computer]) values " & _
" ('" & Me.lblUser.Text & "','" & Me.lblName.Text & "','" & Me.lblsurName.Text & "','" & Me.lbldm.Text & "','" & Me.lblnumber.Text & "','" & Me.lblyear.Text & "','" & Now & "','" & Me.txtcomputer.Text & "')"
objCmd = New SqlCeCommand
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
|
 |
 |
 |
 |
Date :
2012-03-08 22:31:08 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากๆ เลยครับ
|
 |
 |
 |
 |
Date :
2012-03-08 22:42:12 |
By :
Mikkola |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 05
|