Been using the code below to return a single record from the database. I have read that ExecuteScalar is the right way to return a single record. I have never been able to get ExecuteScalar to work though. How would I change this to return a single value in VB.Net using ExecuteScalar?
Dim oracleConnection As New OracleConnection
oracleConnection.ConnectionString = LocalConnectionString()
Dim cmd As New OracleCommand()
Dim o racleDataAdapter As New OracleClient.OracleDataAdapter
cmd.Connection = oracleConnection
cmd.CommandText = "FALCON.CMS_DATA.GET_MAX_CMS_TH"
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add(New OracleParameter("i_FACID_C", OracleType.Char)).Value = facilityShortName
cmd.Parameters.Add(New OracleParameter("RS_MAX", OracleType.Cursor)).Direction = ParameterDirection.Output
Try
Using oracleConnection
oracleConnection.Open()
Using oracleDataAdapter
oracleDataAdapter = New OracleClient.OracleDataAdapter(cmd)
Dim workingDataSet As DataSet
oracleDataAdapter.TableMappings.Add("OutputSH", "RS_MAX")
workingDataSet = New DataSet
oracleDataAdapter.Fill(workingDataSet)
For Each row As DataRow In workingDataSet.Tables(0).Rows
Return CDate(row("MAXDATE"))
Next
End Using
End Using