I have a stored procedure which retrieves multiple rows of 3 column items. I am retrieving in the format of DataTable. When I debug it it gives me error
Must Declare Scalar variable @Ticket.
But I have already declared that.
Stored procedure :
BEGIN
Declare @Ticket Numeric(28,0)
Declare @SQL VarChar(Max)
Declare @SQLUpdate VarChar(Max)
Set @SQL='Select @Ticket=Ticket,VendorTicket[Vendor Ticket],Comments From dbo.VendorTickets Where NotifyOn <= GetDate() And IsNull(NotifyOn,0)<>0 '
Exec(@SQL)
Set @SQLUpdate='Update dbo.VendorTicket Set NotifyOn=0 Where Ticket=@Ticket'
Exec(@SQLUpdate)
END
Code which calls stored procedure
SqlConnection oConn = null;
DataTable dtReturn = null;
try
{
getConnection(ref oConn, 1);
using (SqlStoredProcedure sspObj = new SqlStoredProcedure("dbo.usp_checkNotification", oConn, CommandType.StoredProcedure))
{
dtReturn = sspObj.ExecuteDataTable();
sspObj.Dispose();
}
closeConnection(ref oConn);
}
Why are you using dynamic SQL?
Just do this
Note that setting a datetime (NotifyOn) to 0 will set it to 1900-01-01.