views:

50

answers:

3

Hi I have a really complicated dynamic query that i want to use to retrieve data from the database I am working in .net 3.5 sql server 2008

i created a stored procedure that accepts a varchar(max) as input parameter and does

execute (@SqlQuery)

it executes but does not return anything

I really would like to use LINQ as all my project is implemented using linq

Any Idea how to do it

what is the problem?

A: 

If you want to execute raw SQL via LINQ, you should look into the method ExecuteQuery<T>.

Mark Byers
A: 
    using (SqlConnection con = new SqlConnection("server=(local)\\SQLEXPRESSdatabase=MyDatabase;Integrated Security=SSPI"))
    {
        using (SqlCommand cmd = new SqlCommand())
        {

            cmd.Connection = con;
            cmd.CommandText = @sqlcommand actualtext;

            cmd.Parameters.Add(anyParams that are in the query);
            con.open();
            SqlDataReader rdr = cmd.ExecuteReader();

            if (rdr.HasRows)
            {
               rdr.Read();
               //code here reader should have all the data returned that met the select statement
            }

        }
    }        
Laurence Burke
A: 

Read this article, which pretty thoroughly explains dynamic linq to sql

http://www.west-wind.com/Weblog/posts/143814.aspx

Russell Steen