code ที่ได้เขียนไวในตอนแรก
Protected Sub btnrecord_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnrecord.Click
Dim strConn As String
strConn = WebConfigurationManager.ConnectionStrings("CPETC").ConnectionString
'======================================
Dim Con As New SqlConnection(strConn)
Con.Open()
Dim conn As New SqlConnection(strConn)
Dim sql As String = "SELECT dbo.Semaster.Semasterid, dbo.Regis_learn.subjectid, dbo.Regis_learn.Username, dbo.Profiles.Firstname, dbo.Profiles.Lastname FROM dbo.Semaster INNER JOIN dbo.Regis_learn ON dbo.Semaster.Semasterid = dbo.Regis_learn.semasterid INNER JOIN dbo.Profiles ON dbo.Regis_learn.Username = dbo.Profiles.Username WHERE (subjectid = '" & Request.QueryString("subjectid") & "') "
Dim adapter As SqlDataAdapter
adapter = New SqlDataAdapter(sql, conn)
Dim ds As New DataSet()
adapter.Fill(ds, "test")
Dim MaxRow As Integer = ds.Tables("test").Rows.Count
Dim i As Integer
Dim ds1 As New DataSet()
For i = 0 To MaxRow - 1
Dim Username As String
Dim Semasterid As String
Dim Subjectid As String
Dim Grade As String
Username = ds.Tables(0).Rows(i)(2).ToString()
Semasterid = ds.Tables(0).Rows(i)("semasterid").ToString()
Subjectid = ds.Tables(0).Rows(i)("subjectid").ToString()
Grade = Request("Select1" + i.ToString)
Dim sqlsub As String = " SELECT dbo.Semaster.Semasterid, dbo.Regis_grade.subjectid, dbo.Regis_grade.username, dbo.Profiles.Firstname, dbo.Profiles.Lastname"
sqlsub = sqlsub + " FROM dbo.Semaster INNER JOIN"
sqlsub = sqlsub + " dbo.Regis_grade ON dbo.Semaster.Semasterid = dbo.Regis_grade.semasterid INNER JOIN"
sqlsub = sqlsub + " dbo.Profiles ON dbo.Regis_grade.username = dbo.Profiles.Username WHERE subjectid = '" & Request.QueryString("subjectid") & "' AND dbo.Regis_grade.username='" & Username & "'"
Dim adapter1 As SqlDataAdapter
adapter1 = New SqlDataAdapter(sqlsub, conn)
adapter1.Fill(ds1, "test")
Dim iMax As Integer = ds1.Tables("test").Rows.Count
If iMax = 0 Then
'Dim Firstname As String
'Dim Lastname As String
addgrade(Semasterid, Subjectid, Username, Grade)
Label1.Text = "บันทึกผลการเรียนเรียบร้อย"
Label1.ForeColor = Drawing.Color.Red
Con.Close()
End If
Next
End Sub
นู๋ต้องการ Insert ข้อมูลตามรูปภาพค่ะ ในตอนแรกไม่มีฟิลด์ของ year มาเพิ่มทีหลัง