Skip to content

Linq to SQL does not return INT values from SQL Server

C B

C B

Asked Jun 22, 2011, 1:48 PM EDT8 answers
Share
LinkedInX
Hello

I cannot get INT values to appear in my WPF datagrid when I use Linq to SQL.  Varchar values appear, from the same table, with out issue.

Where am I going wrong?  Do I have to add some code to convert the INT to system.int32. 

Thanks for your time.

Example of WPF databinding:

<!-- This is the INT value, no values returned-->
  <my:DataGridTextColumn Binding="{Binding  Path=Key_Word_int}" IsReadOnly="True"

  Header="Major System Number" Width="SizeToHeader" />

<!-- This is the Varchar value, values returned-->
  <my:DataGridTextColumn Binding="{Binding Path=Key_Word_Ref}"

  Header="Major System Reference" Width="SizeToHeader" />

Example of Ling to SQL:

  L2SMSDataContext cd = new L2SMSDataContext();

  var dbMS = (from p in cd.Key_Words
  select p).Take(10);

  MSGrid.ItemsSource = dbMS;
  MSInfo.Content = "MS Data Loaded";

8 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Suthish Nair
    0
    are you sure, dbMS contains that record?
    0
  • 0
    var dbMS = (from p in cd.Key_Words
      select p.Key_Word_int).Take(10);

    Please try to select only the particular int column and check the result in dbMS object.
    0
  • C B
    0
    Thanks for the replies.

    Suthish:  Yes the dbMS contains that record.  I created a table with 2 columns i.e. Key_Word_int, Key_Word_Ref.

    Murali:  I will try selecting the particular int column.  I will do this when I get back from work.

    I am using C# 2008 Express (would that make any difference?).

    Thanks

    C
    0
  • 0
    No. Visual C# 2008 does not make any difference here.
    0
  • C B
    0
    Hello

    It must be something wrong with the table in SQL server express.  I created another Datagrid with WPF using Northwind.  From the Orders table I choose EmployeeID.  EmployeeID has the exact configuration as Key_Word_Int in SQL Server express.

    EmployeeID returns INT values without any issues.  Bashing my head against a brick wall is very appealing at this moment.

    Thanks for your time, I am going to start from scratch again.

    Cheers

    C
    0
  • Suthish Nair
    0
    Is that because of an extra space " " between Binding and Path "{Binding Path=Key_Word_int}". :)
    0
  • C B
    0
    Hi

    Good spot but no cigar.  I took out the extra space and still got nothing.  I think it has to be something with the table in SQL Server Express.  I going to recreate the Database and see what happens.

    I will class this post as closed.

    Thanks

    C
    0
  • C B
    0
    Hello

    I have found the problem and it was a very simple one.  The word "int" should be "Int" in the XAML code, since the name of the table in SQL Server is called "Key_Word_Int". 

    A simple mistake which I will take note of for future reference.

    The code should read like this:

    <!-- This is the INT value, no values returned-->
      <my:DataGridTextColumn Binding="{Binding  Path=Key_Word_Int}" IsReadOnly="True"


    Yes, I do feel dumb!

    Thanks

    C
    0