我对编程很新,所以请保持温和。我试图存储对手'的价值。这是tblOrders中唯一标识符到opponentID 在这里我称之为..
Dim opponentID As Guid = order.SelectOpponentID(orderID)
下面是我尝试的代码,但是我得到了System.InvalidCastException:指定的强制转换是无效的。如果有人能为我调整一下,我会非常感激..
VB代码
ArrayList
SQL CODE
Public Function SelectOpponentID(ByVal orderID As Guid)
Dim DBConnect As New DBConn
Using db As DbConnection = DBConnect.Conn("DBConnectionString")
Dim cmd As SqlCommand = DBConnect.Command(db, "SelectOpponentID")
cmd.Parameters.Add(New SqlParameter("orderID", SqlDbType.UniqueIdentifier, ParameterDirection.Input)).Value = orderID
db.Open()
Dim DR As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Dim opponentID As Guid
While DR.Read
opponentID = DR("opponent")
End While
DR.Close()
DR = Nothing
cmd.Dispose()
cmd = Nothing
db.Dispose()
db.Close()
End Using
End Function
答案 0 :(得分:1)
试试这个:
opponentID = DR.GetGuid(DR.GetOrdinal("opponent"))