Results 1 to 9 of 9

Thread: DataCol problems?

  1. #1

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    DataCol problems?

    I have a DataColumn and call the MaxLength Property on it to get the length of data that can go into a field ... but it always returns -1 (yes even on a string field)...

    What's going on? - I can get other properties out of it no probs...

    Kris

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: DataCol problems?

    Did you set the MaxLength Property. MSDN says that

    The maximum length of the column in characters. If the column has no maximum length, the value is –1 (default).


    The MaxLength property is ignored for non-text columns.
    Please mark you thread resolved using the Thread Tools as shown

  3. #3

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: DataCol problems?

    the column is a text field in an sql database - and regardless if i set it through code or not i want to get the max length of data that i can enter

    Thanks
    Kris

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: DataCol problems?

    If you want the MaxLength property of the DataColumns set when you call Fill on a DataAdapter then you need to set the adapter's MissingSchemaAction property to AddWithKey, rather than the default Add.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: DataCol problems?

    If I do that it says things like "column 'Medicare Expiry Date' is read only" - even when I am not attempting to change the column

    That happens when i go:

    vb Code:
    1. Return From xItem As System.Data.DataRowView In BS _
    2.                Where xItem.Item("Medicare Expiry Date") <= DateAdd(DateInterval.Day, 7, Date.Today) _
    3.                Select xItem

    Thanks again
    Kris

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: DataCol problems?

    Quote Originally Posted by i00 View Post
    If I do that it says things like "column 'Medicare Expiry Date' is read only" - even when I am not attempting to change the column

    Thanks again
    Kris
    It just spontaneously says that, or it says that when you do something specific? What exactly would that something be?

    If I seem abrupt the please consider the fact that, while this might be the first time today you have failed to provide all the relevant information, it's the tenth time today I've had to ask someone to post information that they really should have thought to post in the first place, and it gets a bit old. If you just post the cause without the effect or the effect without the cause then you haven't provided all the relevant information.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: DataCol problems?

    it does it when i call the .count on that enum actually so
    vb Code:
    1. Dim MedicareExp = From xItem As System.Data.DataRowView In BS _
    2.                Where xItem.Item("Medicare Expiry Date") <= Date.Today _
    3.                Select xItem
    4. msgbox(MedicareExp.count)'ERROR HAPPENS ON THIS LINE

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: DataCol problems?

    I just tried the following code, with and without the highlighted line, and it worked fine for me.
    Code:
    Using connection As New SqlConnection(builder.ConnectionString)
        Using adapter As New SqlDataAdapter("SELECT * FROM PolicyHistory", _
                                            connection)
            Dim table As New DataTable
    
            adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey
            adapter.Fill(table)
            Me.BindingSource1.DataSource = table
    
            Dim rows = From row In Me.BindingSource1.Cast(Of DataRowView)() _
                       Where CDate(row("StartDate")) <= Date.Today
    
            MessageBox.Show(rows.Count().ToString())
        End Using
    End Using
    There's obviously something else at play in your case.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: DataCol problems?

    hrm interesting ... thats basically what i have ... hrm...

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