sqlcommand stored procedure returning date Parameter

  • Thread starter Thread starter Gerry Viator
  • Start date Start date
G

Gerry Viator

Hi all,

Trying to just return a date, keep getting vb.net error on
"Dim DataReader As SqlDataReader = EusCmd.ExecuteReader()"

***VB.net

Private Function getLastDate() As DateTime

FunctionMainConnection()

Dim EusCmd As New SqlCommand("getlastdate", MainSQLConn)
MainSQLConn.Open()

Dim DataReader As SqlDataReader = EusCmd.ExecuteReader()

EusCmd.CommandType = CommandType.StoredProcedure
EusCmd.CommandTimeout = 20
EusCmd.Connection = MainSQLConn
EusCmd.Parameters.Add("@out", SqlDbType.DateTime) '
Output Parameter
EusCmd.Parameters("@out").Direction = ParameterDirection.Output

While DataReader.Read
getLastDate = DataReader.GetString(0)
End While

DataReader.Close()
MainSQLConn.Close()

End Function

**********SQL stored procedure

CREATE PROCEDURE getlastdate
@lastd datetime out
AS
set @lastd = (select CONVERT( CHAR(12), max(incrementDate),101) from
EusBatchIncrement)
GO

Thanks for your help
Gerry
 
Thanks for your help

still the same error when I move that line like you said.
?

thanks
Gerry
 
Thanks

All I'm trying to do is return date. Example: stored procedure returns
07/08/2004.

Error is on this line in VB
" Dim DataReader As SqlDataReader = EusCmd.ExecuteReader()"



Private Function getLastDate() As DateTime

FunctionMainConnection()

Dim EusCmd As New SqlCommand("getlastdate", MainSQLConn)
MainSQLConn.Open()
EusCmd.CommandType = CommandType.StoredProcedure
EusCmd.CommandTimeout = 20
EusCmd.Connection = MainSQLConn
EusCmd.Parameters.Add("@out", SqlDbType.DateTime) '
Output Parameter
EusCmd.Parameters("@out").Direction = ParameterDirection.Output

Dim DataReader As SqlDataReader = EusCmd.ExecuteReader()

While DataReader.Read
getLastDate = DataReader.GetString(0)
End While

DataReader.Close()
MainSQLConn.Close()

End Function

**********SQL stored procedure

CREATE PROCEDURE getlastdate
@lastd datetime out
AS
set @lastd = (select CONVERT( CHAR(12), max(incrementDate),101) from
EusBatchIncrement)
GO

Thanks for your help
Gerry
 
Gerry,
Your SP is looking for @lastd and your are supplying @out for the
parameter name. It's going to have a hard time matching those names.

Ron Allen
 
Back
Top