Vb.net 将数据插入关系表
我有三个关系表,下面是我想要做的Vb.net 将数据插入关系表,vb.net,sql-server-2008-r2,Vb.net,Sql Server 2008 R2,我有三个关系表,下面是我想要做的 将数据插入表中 获取最后插入的行id 将最后插入的行id插入到关系表中 我收到以下错误:列名LastInsertID无效 Private Sub cmdSave_Click(sender As Object, e As EventArgs) Handles cmdSave.Click cn.Open() Using cmd As New SqlClient.SqlCommand("INSERT INTO ParentInformation(
Private Sub cmdSave_Click(sender As Object, e As EventArgs) Handles cmdSave.Click
cn.Open()
Using cmd As New SqlClient.SqlCommand("INSERT INTO ParentInformation(father_firstname,father_lastname,father_mi,father_occupation " _
& " father_telnum,mother_firstName,mother_lastname,mother_mi,mother_occupation,mother_telnum," _
& " contact_firstname, contact_lastname,contact_MI, contact_Address, contact_telnum) " _
& " VALUES('" & txtFatherGN.Text & "', '" & txtFatherLN.Text & "','" & txtFatherMI.Text & "'," _
& " '" & txtFatherOccupation.Text & "','" & txtFatherCP.Text & "','" & txtMotherGN.Text & "' ," _
& " '" & txtMotherLN.Text & "','" & txtMotherMI.Text & "','" & txtMotherOccupation.Text & "'," _
& "'" & txtMotherCP.Text & "','" & txtContactGN.Text & "','" & txtContactLN.Text & "'," _
& "'" & txtContactMI.Text & "', '" & txtContactAddress.Text & "','" & txtContactCP.Text & "'; dim lastInsertedID as string = SELECT LAST_INSERT_ID())", cn)
End Using
Using cmd As New SqlClient.SqlCommand("INSERT INTO studentInformation(Surname,firstName, " _
& " MiddleName,Address,Birthday,Gender,Nationality,Birthplace, " _
& " Telnum,SchoolLastAttended,Note,Image,ParentID) " _
& " VALUES('" & txtStudLN.Text & "', '" & txtStudFN.Text & "','" & txtStudMN.Text & "'," _
& " '" & txtAddress.Text & "','" & dtpBirthday.Text & "','" & newStudent & "' ," _
& " '" & cboNationality.Text & "','" & txtPlaceOfBirth.Text & "','" & txtStudentCP.Text & "'," _
& "'" & cboSchoolYear.Text & "','" & cboGradeLevel.Text & "','" & txtSWG.Text & "'," _
& "'" & txtSchoolAddress.Text & "', '" & txtNote.Text & "',@StudentPic,lastInsertedID;dim lastInsertedID as string = SELECT LAST_INSERT_ID())", cn)
End Using
Using cmd As New SqlClient.SqlCommand("INSERT INTO StudentHistory(SchoolYear,Levels,Section,DateEnrolled ,StudentID) " _
& " VALUES('" & cboSchoolYear.Text & "','" & cboGradeLevel.Text & "', " _
& "'" & cboSection.Text & "','" & dtpEnrollment.Text & "', lastInsertedID)", cn)
cmd.Parameters.Add(New SqlClient.SqlParameter("@StudentPic", SqlDbType.Image)).Value = IO.File.ReadAllBytes(a.FileName)
i = cmd.ExecuteNonQuery
If (i > 0) Then
MsgBox("Save " & i & "Record Successfully")
'clear()
End If
End Using
cn.Close()
End Sub
有人能帮我修一下吗。提前感谢尝试更换
,lastInsertedID;dim lastInsertedID as string = SELECT LAST_INSERT_ID()
与
数据库服务器将理解last_INSERT_ID()的最后一个值。我现在遇到了这个错误。。最后一个\u INSERT\u ID无法识别带有此代码行的生成函数名[code]i=cmd.ExecuteNonQuery[/code]
,LAST_INSERT_ID()