none
simple noob linq to sql cast problem RRS feed

  • Question

  • hi,

    So i'm not all that good with link. Here's what my .dbml looks like and heres the error. Could you guys help plz!





    -Gideon MCTS:Windows Development and C# geek.
    Friday, December 11, 2009 5:35 PM

Answers

  • ok, so this worked:
    DataClassesDataContext dat = new DataClassesDataContext(Settings.Default.ConnectionString);
                DataTable tab = new DataTable();
                tab.Columns.Add("ID", typeof(int));
                tab.Columns.Add("AppName", typeof(string));
                tab.Columns.Add("Description", typeof(string));
                DataRow dr = tab.NewRow();
                var q = from c in dat.giddy_Apps
                        orderby c.ID descending
                        select new { theID = c.ID, theAppName = c.AppName.Trim(), theDes = c.Description };
                foreach (var c in q)
                {
                    dr["ID"] = c.theID;
                    dr["AppName"] = c.theAppName;
                    dr["Description"] = c.theDes;
                    tab.Rows.Add(dr);
                }
                Repeater1.DataSource = tab;
                Repeater1.DataBind();
    Lesson learned: If at first, or the 100th try, the type doesn't work... create a new one! =)
    -Gideon MCTS:Windows Development and C# geek.
    Saturday, December 12, 2009 6:55 AM

All replies

  • foreach(giddy_App in b)
    {
    ...

    -DishanF-
    Saturday, December 12, 2009 4:38 AM
  • nope, that doesn't seem to work either. The same "specified cast is not valid" error shows up.

      DataClassesDataContext dat = new DataClassesDataContext(Settings.Default.ConnectionString);
    Line 16:             var b = from d in dat.giddy_Apps select d;
    Line 17:             foreach (giddy_App t in b)
    Line 18:             {
    Line 19:                 t.AppName = t.AppName.Trim();

    -Gideon MCTS:Windows Development and C# geek.
    Saturday, December 12, 2009 6:13 AM
  • ok, so this worked:
    DataClassesDataContext dat = new DataClassesDataContext(Settings.Default.ConnectionString);
                DataTable tab = new DataTable();
                tab.Columns.Add("ID", typeof(int));
                tab.Columns.Add("AppName", typeof(string));
                tab.Columns.Add("Description", typeof(string));
                DataRow dr = tab.NewRow();
                var q = from c in dat.giddy_Apps
                        orderby c.ID descending
                        select new { theID = c.ID, theAppName = c.AppName.Trim(), theDes = c.Description };
                foreach (var c in q)
                {
                    dr["ID"] = c.theID;
                    dr["AppName"] = c.theAppName;
                    dr["Description"] = c.theDes;
                    tab.Rows.Add(dr);
                }
                Repeater1.DataSource = tab;
                Repeater1.DataBind();
    Lesson learned: If at first, or the 100th try, the type doesn't work... create a new one! =)
    -Gideon MCTS:Windows Development and C# geek.
    Saturday, December 12, 2009 6:55 AM