Neven Draskovic

Neven Draskovic

  • NA
  • 117
  • 138.1k

Using SQL stored procedures in C# WinForm appllication

Dec 17 2012 3:34 AM
Hey

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)