Hello people, I need your advice, what to do. I use LINQ stored procedure to select all data from sql table to DataGridView:

EtiketyLINQDataContext EtiketyData = new EtiketyLINQDataContext(); 
IEnumerable VypisDat = EtiketyData.Vypis("Cislo", "Typ", "Hrubka", "MaterialTyp");  

LINQdataGridView.DataSource = VypisDat; 

The problem occurs with this line:

IEnumerable VypisDat = EtiketyData.Vypis("Cislo", "Typ", "Hrubka", "MaterialTyp");

...saying 'Cannot implicitly convert type 'int' to 'System.Collections.IEnumerable'.

The stored procedure "Vypis" looks like this:

    @Column1 varchar(50), 
    @Column2 varchar(50), 
    @Column3 varchar(50), 
    @Tablename varchar(50) 
    /*Vypis vsetkych stlpcov tabulky*/ 
    EXEC ('SELECT ' + @Column1 + ', '+@Column2+', '+@Column3+' FROM '+@Tablename)    

I realize that the problem can be also in bad type in design view of the table, where the code is like this:

[Function(Name = "dbo.Vypis")]
        public [B]int[/B] Vypis([Parameter(Name = "Column1", DbType = "VarChar(50)")] string column1, [Parameter(Name = "Column2", DbType = "VarChar(50)")] string column2, [Parameter(Name = "Column3", DbType = "VarChar(50)")] string column3, [Parameter(Name = "Tablename", DbType = "VarChar(50)")] string tablename)
            IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), column1, column2, column3, tablename);
            return (([B]int[/B])(result.ReturnValue));

But here, when I change type on System.Collections.IEnumerable, I get message:

'System.Collections.IEnumerable' is not a valid return type for a mapped stored procedure method'.

I'm now completely lost, what shall I do... I hope, the explanation is not complicated.


Edited 3 Years Ago by happygeek: fixed formatting

The problem would seem to be

return ((int)(result.ReturnValue));

In old days thats probably a pointer to the result, but in .net youve told it to be an int, so an int it is.

Try changing it to

return ((IEnumerable<Order>)(result.ReturnValue));

OK, but now I get this message:

The type or namespace name 'Order' could not be found (are you missing a using directive or an assembly reference?)

I think my stored procedures have been tweaked enough, maybe the int type was good enough... and now comes the question how to bind data to datagrid view, but following code is not good:

EtiketyLINQDataContext EtiketyData = new EtiketyLINQDataContext();
var VypisDat = EtiketyData.Vypis(3,"Cislo", "Typ", "Hrubka", "MaterialTyp");
LINQdataGridView.DataSource = VypisDat;


You said it wasnt working - it cant be good enough if it doesnt work, can it?

So, your new code, how about letting us have the error code you get, rather than trying constantly to recreate half an application to duplicate the need for the code you have?

Yes, I've found the problem. Here on this link:


I learned that, what you wrote "Order" in IEnumerabler<Order> has to be the name of the table in my database. For me it was "MaterialTyp", so changed it from: return ((int)(result.ReturnValue)); to: return ((IEnumerable<MaterialTyp>)(result.ReturnValue)); and then changed it on other two places of the code and now it works.

Thanks a lot for your patience :), you helped me.

This question has already been answered. Start a new discussion instead.