LINQ stored procedure to select all data from table to datagridview

Oct 6 2008 7:14 AM
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:

ALTER PROCEDURE dbo.Vypis
(
@Column1 varchar(50),
@Column2 varchar(50),
@Column3 varchar(50),
@Tablename varchar(50)
)
AS
/*Vypis vsetkych stlpcov tabulky*/
EXEC ('SELECT ' + @Column1 + ', '+@Column2+', '+@Column3+' FROM '+@Tablename)
RETURN

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 int 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 ((int)(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.

matej

Answers (1)