 |
|
คือค่าของตารางRegisterแรกคอลัมน์ resub_id เป็นคีย์หลักโดยสั่งให้รันอัตโนมัติ
อยากจะเอาค่า Register คอลัมน์ resub_id ไปใส่ตาราง Study ต้องทำอย่างไรค่ะ


โค้ด
Code (VB.NET)
Try
For i As Integer = 0 To dgvImport.RowCount - 1
strsql = "INSERT INTO Student(nisit_id,nisit_name,nisit_major)"
strsql &= "VALUES('" & dgvImport.Rows(i).Cells(1).Value & "' , '" & dgvImport.Rows(i).Cells(2).Value & "' , '" & dgvImport.Rows(i).Cells(3).Value & "')"
With cmd
.Connection = con
.CommandText = strsql
.CommandType = CommandType.Text
.ExecuteNonQuery()
End With
Next
Catch
MsgBox("มีข้อมูลนิสิตอยู่แล้ว")
End Try
Try
' เพิ่มข้อมูลลงตาราง(Register)
strsql = "INSERT INTO Register(sub_id,re_year,term,lectures,laboratory)"
strsql &= "VALUES('" & txtSub_id.Text & "' , '" & txtShowYear.Text & "' , '" & txtShowTerm.Text & "' , '" & txtLectures.Text & "' , '" & txtLab.Text & "')"
With cmd
.Connection = con
.CommandText = strsql
.CommandType = CommandType.Text
.ExecuteNonQuery()
End With
Catch ex As Exception
End Try
For i As Integer = 0 To dgvImport.RowCount - 1
'เพิ่มข้อมูลลงตาราง Study
strsql = "INSERT INTO Study(resub_id,nisit_id)"
strsql &= "VALUES('" & txtRe_id.Text & "' , '" & dgvImport.Rows(i).Cells(1).Value & "')"
With cmd
.Connection = con
.CommandText = strsql
.CommandType = CommandType.Text
.ExecuteNonQuery()
End With
Next
Tag : .NET, Ms SQL Server 2008, VS 2010 (.NET 4.x)
|
|
 |
 |
 |
 |
Date :
2015-04-07 12:49:40 |
By :
Preeyapan |
View :
781 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |