cancel
Showing results for 
Search instead for 
Did you mean: 

Fill DataTable using stored procedure

lars_jnsson
Active Participant
0 Kudos

I'm getting an error "Invalid query tree " when I try to load data into a DataTable from a SQL stored procedure:

DataTable dt = myForm.DataSources.DataTables.Add("MYTABLE");

dt.ExecuteQuery("EXEC sp_myprocedure @Par1 = 10");

The SQL stored procedure creates a temporary table and fills it with data using several CTE update statements. Finally a select * from the table is returned.

The procedure works fine when run in the SQL Management Studio.

Isn't it possible to fill data into a DataTable using a SP?

SAP2007 PL 44, SQL2005, VS2008, C#, .NET 3.5

Regards

Lars Jönson

Accepted Solutions (0)

Answers (2)

Answers (2)

lars_jnsson
Active Participant
0 Kudos

No, that's not the problem (I've tried it).

I found it! I forgot to SET NOCOUNT ON. That helped!

Regards

Lars

Former Member
0 Kudos

Hi,

Try to create a string value that set the procedure and in executequery set the string

For example

string osp=string.Format("EXEC sp_myprocedure @Par1 = ","10");

dt.ExecuteQuery(osp);

hope it helped you

Georgex