467,207 Members | 1,309 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,207 developers. It's quick & easy.

How to Retrieve MaxLength of a Column?

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

Jun 14 '07 #1
  • viewed: 1674
Share:
1 Reply
Mel
On Jun 14, 9:01 am, Mel <MLights...@gmail.comwrote:
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

Jun 14 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by sql | last post: by
7 posts views Thread by ray@cape.com | last post: by
1 post views Thread by Anthony | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.