Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2004
    Location
    Midwest
    Posts
    6

    Unanswered: ASP page that reads a field length from MySql

    I've searched as much as I can to find how to retrieve the field length from a field in a MySql database.

    I want to build a page that will pull information from a database table. I have found the code to display the field names, but want to use the field length of the original mySql field to determine the maxlength of the textbox for my add page. If the answer has already been posted, I apologize. Thanks in advance!

    The page would look something like this:

    ID: [ ]
    Name: [ ]
    Description [ ]

    I used the [] to represent the size of the textboxes.

  2. #2
    Join Date
    Feb 2004
    Location
    Midwest
    Posts
    6

    Code included:

    Sorry, didn't post the code before, but here it is.

    where the comment is below is where the field size would come in very handy:

    Set conn = Server.CreateObject("ADODB.Connection")
    conn.open= "driver={MySQL ODBC 3.51 Driver};server=localhost;uid=user;pwd=password;dat abase=myDb;Option=16387;"
    mySql = "Select * From " & strTbl
    set rsTbl = conn.Execute(mySql)

    Response.Write "<table border=1>"
    For Each Field in rsTbl.Fields
    %>
    <tr><td><% =Field.Name %></td><td><input type="text" name="<% =Field.Name %>" size="40" maxlength="<% 'Code to retrieve field size would go here%>" ></td></tr>
    <%
    Next
    Response.Write "</table><br>"

  3. #3
    Join Date
    Dec 2003
    Posts
    454
    Len(string) returns the number of characters in a string.

  4. #4
    Join Date
    Feb 2004
    Location
    Midwest
    Posts
    6
    The Len() statement did not retrieve the value from the database table properties. When viewing the table with MySql Control Center for example, a field may be defined as text with a maximum length of 40. I would like to know how my ASP page can retrieve this information from the MySql database properties. Maybe this is not possible, I don't know. I do thank you for your response.

  5. #5
    Join Date
    Dec 2003
    Posts
    454
    <%= Field.DefinedSize %> displays the defined size of the Field object. It works with MS SQL server 2000.

  6. #6
    Join Date
    Feb 2004
    Location
    Midwest
    Posts
    6

    Smile

    Thank you SO much, that is it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •