When I am running the stored procedure below in SMSS, it works and returns a nice result.
SQL:
EXEC @return_value = [dbo].[xxxxxx_EnergiAllTags]
@SegmentResponseID = 'xxxxxxxxxx'
But when I am trying to run the stored procedure from my C# code, I get an error:
Invalid column name 'Value'
This is my code:
public DataSet GetQuery(string batchNr)
{
SqlConnection conn = new SqlConnection("xxxxxxxx");
SqlCommand command = new SqlCommand("xxxxxx_EnergiAllTags", conn);
SqlDataAdapter da = new SqlDataAdapter(command);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("@SegmentResponseID", batchNr));
DataSet ds1 = new DataSet();
command.CommandTimeout = 60000;
try
{
da.Fill(ds1);
return ds1;
}
catch (Exception e)
{
string ex = e.Message;
throw;
}
}
Can anyone that might have a clue help me figure out what the problem is?
****Update as Req*****
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[xxxxxx_EnergiAllTags]
@SegmentResponseID AS VARCHAR(MAX)
AS
BEGIN
SET NOCOUNT ON;
CREATE TABLE #temp (TagName NVARCHAR(MAX),
StartValue NVARCHAR(MAX),
EndValue NVARCHAR(MAX),
Usage NVARCHAR(MAX)
)
INSERT INTO #temp
EXEC [dbo].[xxxxxx_EnergyTagForBatch] @BatchID = @SegmentResponseID,
@TagName = 'T06C02D01E02FQ000.PV'
INSERT INTO #temp
EXEC [dbo].[xxxxxx_EnergyTagForBatch] @BatchID = @SegmentResponseID,
@TagName = 'T06C02D01E02FQ001.PV'
SELECT * From #temp
DROP TABLE #temp
END
Okay i have figured out the problem.
The 2 SP i have both had a temp table called #temp and while i believe they should be localized to each instance, they were not, and mixed, and by that time they gave an error.
Solution, make sure that there are not temp tables with the same name using in the string of stored-procedure you might call.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.