Click here to Skip to main content
15,905,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,,,
I want to Convert this coding this give error...any body help me..

C#
DataTable GetMenuData(int id)
    {
        //using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CMSConnectionString"].ConnectionString))
        //{
        //    SqlDataAdapter dadCats = new SqlDataAdapter("SELECT * FROM MenuDetails where MenuId=1 and Status=1 and ParentID=" + id + "", con);
        //    DataSet dst = new DataSet();
        //    dadCats.Fill(dst);
        //    return dst.Tables[0];


        //}
        using (NKDataContext db = new NKDataContext())
        {
            var dt = db.GetMenuDetails().Where(x=>x.MenuID==1);

            return dt.CopyToDataTable();
        }
    }


Please correct Uncommented Coding...

Thank's in Advance.
Posted
Comments
Nickos_me 25-Nov-11 3:41am    
What is type of error?

Is "GetMenuDetails" a method or table name??


you should follow this way...

C#
DataContext db = new DataContext();

var a= db.TableName.Where(Condition);
return a;



-Sagar Solanki
 
Share this answer
 
Comments
Herman<T>.Instance 26-Aug-11 5:17am    
a private method
Niranjankr 26-Aug-11 7:58am    
Method Name ...
and its return type is DataTable..
sasolanki007 7-Sep-11 21:20pm    
have you tried the way I recommended?
public static DataTable LINQToDataTable<t>(IEnumerable<t> varlist)
    {
        DataTable dtReturn = new DataTable();         
        PropertyInfo[] oProps = null;
        if (varlist == null) return dtReturn;
        foreach (T rec in varlist)
        {
            if (oProps == null)
            {
                oProps = ((Type)rec.GetType()).GetProperties();
                foreach (PropertyInfo pi in oProps)
                {
                    Type colType = pi.PropertyType;
                    if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable<>)))
                    {
                        colType = colType.GetGenericArguments()[0];
                    }
                    dtReturn.Columns.Add(new DataColumn(pi.Name, colType));
                }
            }
            DataRow dr = dtReturn.NewRow();
            foreach (PropertyInfo pi in oProps)
            {
                dr[pi.Name] = pi.GetValue(rec, null) == null ? DBNull.Value : pi.GetValue
                (rec, null);
            }
            dtReturn.Rows.Add(dr);
        }
        return dtReturn;
    }</t></t>
 
Share this answer
 
v2
Comments
RaviRanjanKr 25-Nov-11 3:21am    
[Edited]Your code is wrapped in "pre" tag[/Edited]
A Suggestion :- Always try to use Pre tag to wrapped your code. it will make better readability of your code to other user.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900