How to Retrieve MaxLength of a Column?

M

Mel

Anyone know how I would retrieve the MaxLength property of a column in
my Access Database table? I know how to retrieve table data, for
example the "Quote #" field in my example code below, but I have never
attempted to access a property of a field.

'Beginning of my Code Example
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\support\webbmq.mdb;"
Dim strSel As String = "SELECT * FROM [Quotes] "
Dim conWebOrdNum As New System.Data.OleDb.OleDbConnection(strConn)
Dim Rec As System.Data.OleDb.OleDbDataReader
Dim cmdRead As New System.Data.OleDb.OleDbCommand(strSel,
conWebOrdNum)
conWebOrdNum.Open()
Rec = cmdRead.ExecuteReader()
Rec.Read()
Session("OrdNum") = Rec("Quote #")
Rec.Close()
'End of my Code Example
 
M

Mel

Anyone know how I would retrieve the MaxLength property of a column in
my Access Database table? I know how to retrieve table data, for
example the "Quote #" field in my example code below, but I have never
attempted to access a property of a field.

'Beginning of my Code Example
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\support\webbmq.mdb;"
Dim strSel As String = "SELECT * FROM [Quotes] "
Dim conWebOrdNum As New System.Data.OleDb.OleDbConnection(strConn)
Dim Rec As System.Data.OleDb.OleDbDataReader
Dim cmdRead As New System.Data.OleDb.OleDbCommand(strSel,
conWebOrdNum)
conWebOrdNum.Open()
Rec = cmdRead.ExecuteReader()
Rec.Read()
Session("OrdNum") = Rec("Quote #")
Rec.Close()
'End of my Code Example

Nevermind, I figured it out. Here is the code I ended up with.

'Beginning of my Code Example
Dim strConn As String = "Provider=Microsoft.JET.OLEDB.4.0;Data Source
=" & "c:\support\webbmq.mdb"
Dim strRecQuotes As String = "SELECT * FROM [Quotes];"
Dim conQuotes As New System.Data.OleDb.OleDbConnection(strConn)
Dim recQuotes As System.Data.OleDb.OleDbDataReader
Dim comQuotes As New System.Data.OleDb.OleDbCommand(strRecQuotes,
conQuotes)
Dim dt As System.Data.DataTable

conQuotes.Open()
recQuotes = comQuotes.ExecuteReader()
recQuotes.Read()

dt = recQuotes.GetSchemaTable()

'SET THE TEXT BOX MAXLENGTH PROPERTIES TO THE COLUMN LENGTHS DEFINED
IN THE DATABASE
For i = 0 To dt.Rows.Count - 1
If UCase(Trim(dt.Rows(i)("ColumnName"))) = "CUSTOMER" Then
txtCustomer.MaxLength = dt.Rows(i)("ColumnSize")
ElseIf UCase(Trim(dt.Rows(i)("ColumnName"))) = "PROJECT NAME"
Then
txtProjName.MaxLength = dt.Rows(i)("ColumnSize")
ElseIf UCase(Trim(dt.Rows(i)("ColumnName"))) = "SHIP TO ADDRESS
1" Then
txtProjAddr1.MaxLength = dt.Rows(i)("ColumnSize")
ElseIf UCase(Trim(dt.Rows(i)("ColumnName"))) = "SHIP TO ADDRESS
2" Then
txtProjAddr2.MaxLength = dt.Rows(i)("ColumnSize")
ElseIf UCase(Trim(dt.Rows(i)("ColumnName"))) = "SHIP TO CITY"
Then
txtProjCity.MaxLength = dt.Rows(i)("ColumnSize")
ElseIf UCase(Trim(dt.Rows(i)("ColumnName"))) = "SHIP TO ZIPCODE"
Then
txtZip.MaxLength = dt.Rows(i)("ColumnSize")
ElseIf UCase(Trim(dt.Rows(i)("ColumnName"))) = "CUSCONTACT" Then
txtCusContact.MaxLength = dt.Rows(i)("ColumnSize")
ElseIf UCase(Trim(dt.Rows(i)("ColumnName"))) = "CUSPHONE" Then
txtCusPhone.MaxLength = dt.Rows(i)("ColumnSize")
End If
Next
recQuotes.Close()

If Not comQuotes Is Nothing Then
comQuotes.Dispose()
End If
If Not recQuotes Is Nothing Then
recQuotes.Close()
End If
'End of my Code Example
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top