473,466 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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
1 1904
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Edward Mitchell | last post by:
I have a database with text string fields defined by varchar(nnn). When I request from the user the text from a textbox, I'd like to set the maximum number of characters in the textbox to the...
2
by: sql | last post by:
Hi all, I would like to set MaxLength property of asp.net controls on my page based on their corresponding field length in Sql Server table. I know I can get the TableSchema along with the record...
7
by: ray | last post by:
My xsd has the following element: <xs:element name="Company" minOccurs="0"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:minLength value="1" /> <xs:maxLength value="5" />...
1
by: Anthony | last post by:
I am defining the datagridtable style for a grid .... Dim coursekeycol As New DataGridTextBoxColumn coursekeycol.MappingName = COURSEKEYCOLNAME coursekeycol.HeaderText = "" coursekeycol.Width...
3
by: lintolawrance | last post by:
sir, i am starting working with php.i done some programs.but now i have one problem.i do a program like to retrieve the name and email from a phpfile to another.but i can't get. this is the code...
5
by: Ken | last post by:
I'm trying to run a loop to capture column property information from a table in my datasource. Can anybody see where this is going wrong? Dim tbl As New DataTable Dim col As DataColumn Dim x...
9
by: Mel | last post by:
I have 10 columns total. 3 of them are invisible. The rest are read- only BoundFields, 3 of which are editable fields using TemplateFields. Upon editing, I want to validate what the user enters...
14
by: zionlion | last post by:
I want to only retrieve the values of one column in mysql and use these values to plot a graph. I know how to echo these values. However, I am unable to write them seperately. Let's say I have a...
9
by: gavy7210 | last post by:
hello friends i am new to struts. i want to add the user information in the database and then display it back to him. i am using struts 1.2,Eclipse Platform Version: 3.4.2,mySql 5.0.1,jdk...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.