Results 1 to 3 of 3

Thread: [RESOLVED] Problems with Linq-to-SQL

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Posts
    230

    Resolved [RESOLVED] Problems with Linq-to-SQL

    I've created a sql server in the App_Data folder of my solution. I then created a linq to sql dml in a class library and copied the folders across.

    From a Web Form on load method in the root folder I have:
    Code:
            Dim dc As New MilkywayDataContext()
            Dim q = From m In dc.Users _
                    Select m
             UsersGridView.DataSource = q
            ' UsersGridView.DataBind()
    The problem happens when I bind q to the datagrid. Visual basics stops responding and shuts down. This has been a constant occurence all evening anything I try. I'm using
    VS 2012 express.

    Anyone know how I can fix this?

    Cheers

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Posts
    230

    Re: Problems with Linq-to-SQL

    Now I'm getting the following error on the webpage with the same code :

    Specified cast is not valid.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidCastException: Specified cast is not valid.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:


    [InvalidCastException: Specified cast is not valid.]
    System.Data.SqlClient.SqlBuffer.get_Byte() +52
    System.Data.SqlClient.SqlDataReader.GetByte(Int32 i) +62
    Read_User(ObjectMaterializer`1 ) +1765
    System.Data.Linq.SqlClient.ObjectReader`2.MoveNext() +32
    System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +381
    System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
    System.Data.Linq.Provider.BindingList.Create(DataContext context, IEnumerable`1 sequence) +86
    System.Data.Linq.DataQuery`1.GetNewBindingList() +40
    System.Data.Linq.DataQuery`1.System.ComponentModel.IListSource.GetList() +15
    System.Web.UI.DataSourceHelper.GetResolvedDataSource(Object dataSource, String dataMember) +57
    System.Web.UI.WebControls.ReadOnlyDataSource.System.Web.UI.IDataSource.GetView(String viewName) +42
    System.Web.UI.WebControls.DataBoundControl.ConnectToDataSourceView() +145
    System.Web.UI.WebControls.DataBoundControl.OnLoad(EventArgs e) +19
    System.Web.UI.Control.LoadRecursive() +54
    System.Web.UI.Control.LoadRecursive() +145
    System.Web.UI.Control.LoadRecursive() +145
    System.Web.UI.Control.LoadRecursive() +145
    System.Web.UI.Control.LoadRecursive() +145
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772
    Last edited by garry79; Oct 20th, 2012 at 09:07 PM.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2009
    Posts
    230

    Re: Problems with Linq-to-SQL

    I made a change to the underlying database model which meant I had to update the linq-to-sql model also. It works fine now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width