Forums - C# Corner

Forum guidelines
Neven Draskovic

Neven Draskovic

  • 1.2k
  • 117
  • 95.2k

Using SQL stored procedures in C# WinForm appllication

Dec 17 2012 3:34 AM

I'm working on an application that generates certain reports based on data from my clients database. In this database, there are stored procedures whose purpose is to get the necessary data from the database (the queries are very complex and it would be very unpractical to use them as SQLCommands in C#). The problem I'm having is that I can't trigger the stored procedure from my application.
When I try to trigger it directly from code:

sp_AP.CommandText = "EXEC sp_AP"; // I've tried both with and without EXEC command
sp_AP.Parameters.Add(new SqlParameter("@parm1",parm1));
sp_AP.Connection = connection;
SDA.Fill(dtMyDataTable); //SDA is a SqlDataAdapter defined globally

When I execute this code I get the exception "No mapping exists from object type System.Data.DataRow[] to a known managed provider native type.".

When I try to create the new TableAdapter visually in my DataSet, I get the "Invalid object name '#table1'". This part is particularly confusing because when I execute the stored procedure directly on the database it works perfectly.

I've never used stored procedures in my applications before, so please follow any answer with code samples.
Thank you.

Answers (5)

Unlimited Flat-Free License


File APIs for .NET
Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more!