我正在尝试计算已保存数据的记录 这是我的代码:
Dim pl_qry As String
Dim pl_cmd As New Odbc.OdbcCommand
Dim pl_dr As Odbc.OdbcDataReader
If txtPurpose.Text = "PERSONAL LOAN" Then
pl_qry = "select count(purpose) from details where borrower_id = '" & bor_id & "' and purpose = '" & "PERSONAL LOAN" & "'"
pl_cmd.CommandText = pl_qry
pl_cmd.Connection = con
pl_dr = pl_cmd.ExecuteScalar
pl_dr.Read()
If Not pl_dr.IsDBNull(0) Then
MsgBox(pl_dr.GetString(0))
End If
End If
我在这一行得到了错误
pl_dr = pl_cmd.ExecuteScalar
答案 0 :(得分:0)
如果您检查了ExecuteScalar方法,您会发现它将返回SQL第一行的第一列。
问题是您已将结果分配给'OdbcDataReader`
Dim pl_dr As Odbc.OdbcDataReader
但也许你可以直接得到结果:
Int64 result = Convert.ToInt64(cmd.ExecuteScalar())