Results 1 to 8 of 8

Thread: [RESOLVED] [2005] TextBox MaximumSize From SQL Field

  1. #1

    Thread Starter
    Hyperactive Member NPassero's Avatar
    Join Date
    May 2007
    Location
    NJ
    Posts
    272

    Resolved [RESOLVED] [2005] TextBox MaximumSize From SQL Field

    I want to be able to retrieve the field length in the SQL Table and apply that to the text box..

    VarChar(50)
    TextBox1.MaximumSize = 50

    Thanks -
    Last edited by NPassero; May 23rd, 2008 at 10:58 AM.

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

    Re: [2005] TextBox MaximumSize From SQL Field

    How are you getting your data from the database? Are you populating a DataTable? If so then the MaxLength property of the corresponding DataColumn is the value you want.

    By the way, the TextBox property is MaxLength too, not MaximumSize.
    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

  3. #3

    Thread Starter
    Hyperactive Member NPassero's Avatar
    Join Date
    May 2007
    Location
    NJ
    Posts
    272

    Re: [2005] TextBox MaximumSize From SQL Field

    Quote Originally Posted by jmcilhinney
    By the way, the TextBox property is MaxLength too, not MaximumSize.
    - Gotcha

    Ok - Didn't know where that property could be found -

    Dt.Columns(0).MaxLength - and then apply that to the textbox.maxlength

  4. #4

    Thread Starter
    Hyperactive Member NPassero's Avatar
    Join Date
    May 2007
    Location
    NJ
    Posts
    272

    Re: [2005] TextBox MaximumSize From SQL Field

    When I do that - I get a -1 for the MaxLength of the column -

    vb Code:
    1. Dim dtMax as DataTable
    2.     ' selectdt is a function that returns the datatable (used other places and works fine)
    3.     ' oConn is the sql connection - used throughout the program
    4.  
    5. dtMax = SelectDT("SELECT * FROM table_name", oConn)
    6.  
    7. txtShortName.MaxLength = dtMax.Columns("Sname").MaxLength
    8. txtLongName.MaxLength = dtMax.Columns("Name").MaxLength

    Also if I change it to Columns(0) and Columns(1) the MaxLength is still -1

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

    Re: [2005] TextBox MaximumSize From SQL Field

    How exactly are you populating your DataTable?
    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

  6. #6

    Thread Starter
    Hyperactive Member NPassero's Avatar
    Join Date
    May 2007
    Location
    NJ
    Posts
    272

    Re: [2005] TextBox MaximumSize From SQL Field

    using a datadapter

    vb Code:
    1. da.fill (dt)

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

    Re: [2005] TextBox MaximumSize From SQL Field

    You need to set the MissingSchemaAction property of your adapter to AddWithKey in order to retrieve the full schema.
    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

  8. #8

    Thread Starter
    Hyperactive Member NPassero's Avatar
    Join Date
    May 2007
    Location
    NJ
    Posts
    272

    Re: [2005] TextBox MaximumSize From SQL Field

    Got it - Thanks a lot

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