请检查并纠正此代码
Public Function RegisterToEventFAMLY(ByVal p As Participant, ByVal PartcName As String, ByVal Rel As String, ByVal DOB As String, ByVal EVT As String) As String
Using con As New SqlConnection(CONNECTION_STRING)
Dim cmdEv As New SqlCommand("select 'TATA' + RIGHT('0000'+CAST(CHESTNO+1 as VARCHAR(4)),4) from (select top 1 CHESTNO=CAST(RIGHT(CHESTNO,4)as int ) from [SANDBOX].[dbo].[T_HTK_USR_DTLS] order by CHESTNO desc) t where Pno=@IDNo", con)
cmdEv.Parameters.AddWithValue("IDNo", p.ID)
Dim daEv As New SqlDataAdapter(cmdEv)
Dim dtEv As New DataTable
Try
Dim newRowCreated = False
daEv.Fill(dtEv)
Dim drEv As DataRow
If (dtEv.Rows.Count > 0) Then
drEv = dtEv.Rows(0)
Else
drEv = dtEv.NewRow
newRowCreated = True
End If
drEv("Pno") = p.ID
drEv("NAME") = PartcName ''---event code
drEv("BASE_LOCATION") = DOB
drEv("EVENTNM") = Rel
drEv("MAC_ID") = Rel
If (newRowCreated) Then
dtEv.Rows.Add(drEv)
End If
Dim cmdbEv As New SqlCommandBuilder(daEv)
cmdbEv.ConflictOption = ConflictOption.OverwriteChanges
daEv.Update(dtEv)
Catch ex As Exception
Return ex.Message
End Try
End Using
Return "True"
End Function
显示异常错误
无效的列名称'Pno'
答案 0 :(得分:0)
尝试:
select [pno], 'TATA' + RIGHT('0000'+CAST([CHESTNO]+1 as VARCHAR(4)),4) from
(select top 1 [CHESTNO]=CAST(RIGHT([CHESTNO],4) as int ) from
[SANDBOX].[dbo].[T_HTK_USR_DTLS] order by [CHESTNO] desc) t
where [Pno]=@IDNo