|
-
May 23rd, 2008, 10:35 AM
#1
Thread Starter
Hyperactive Member
[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.
-
May 23rd, 2008, 10:39 AM
#2
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.
-
May 23rd, 2008, 10:43 AM
#3
Thread Starter
Hyperactive Member
Re: [2005] TextBox MaximumSize From SQL Field
 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
-
May 23rd, 2008, 11:01 AM
#4
Thread Starter
Hyperactive Member
Re: [2005] TextBox MaximumSize From SQL Field
When I do that - I get a -1 for the MaxLength of the column -
vb Code:
Dim dtMax as DataTable ' selectdt is a function that returns the datatable (used other places and works fine) ' oConn is the sql connection - used throughout the program dtMax = SelectDT("SELECT * FROM table_name", oConn) txtShortName.MaxLength = dtMax.Columns("Sname").MaxLength txtLongName.MaxLength = dtMax.Columns("Name").MaxLength
Also if I change it to Columns(0) and Columns(1) the MaxLength is still -1
-
May 23rd, 2008, 11:23 AM
#5
Re: [2005] TextBox MaximumSize From SQL Field
How exactly are you populating your DataTable?
-
May 23rd, 2008, 11:25 AM
#6
Thread Starter
Hyperactive Member
Re: [2005] TextBox MaximumSize From SQL Field
-
May 23rd, 2008, 11:29 AM
#7
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.
-
May 23rd, 2008, 12:54 PM
#8
Thread Starter
Hyperactive Member
Re: [2005] TextBox MaximumSize From SQL Field
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|