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 -
Printable View
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 -
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.
- GotchaQuote:
Originally Posted by jmcilhinney
Ok - Didn't know where that property could be found -
Dt.Columns(0).MaxLength - and then apply that to the textbox.maxlength
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
How exactly are you populating your DataTable?
using a datadapter
vb Code:
da.fill (dt)
You need to set the MissingSchemaAction property of your adapter to AddWithKey in order to retrieve the full schema.
Got it - Thanks a lot