If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > how to retrieve a table field size on the fly in asp

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-07-04, 20:41
mb92010 mb92010 is offline
Registered User
 
Join Date: Feb 2004
Location: Midwest
Posts: 6
Question how to retrieve a table field size on the fly in asp

Ok,

I have found the code to retrieve the contents and column names from a MySql database in asp. (see the code below) What I am wondering, is if there is a way for the script page to find the size of database field so I can make the maxlength of a textbox equal to this value? Thanks in advance.

Set conn = Server.CreateObject("ADODB.Connection")
conn.open= "driver={MySQL ODBC 3.51 Driver};server=localhost;uid=user;pwd=pwd;database =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 value from database field would go here %> ></td></tr>
<%
Next
Response.Write "</table><br>"
Reply With Quote
  #2 (permalink)  
Old 02-08-04, 16:11
ika ika is offline
Registered User
 
Join Date: Oct 2003
Location: Slovakia
Posts: 482
Re: how to retrieve a table field size on the fly in asp

Quote:
Originally posted by mb92010
Ok,

I have found the code to retrieve the contents and column names from a MySql database in asp. (see the code below) What I am wondering, is if there is a way for the script page to find the size of database field so I can make the maxlength of a textbox equal to this value? Thanks in advance.

Set conn = Server.CreateObject("ADODB.Connection")
conn.open= "driver={MySQL ODBC 3.51 Driver};server=localhost;uid=user;pwd=pwd;database =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 value from database field would go here %> ></td></tr>
<%
Next
Response.Write "</table><br>"
I think this question belong to ASP section...
Reply With Quote
  #3 (permalink)  
Old 02-11-04, 17:16
mb92010 mb92010 is offline
Registered User
 
Join Date: Feb 2004
Location: Midwest
Posts: 6
A reply was given in the ASP section.

<%= Field.DefinedSize %>

This is not neccessasarily just an ASP question. Database knowledge has to be there too. Anyway, thanks for looking at the question. I may have to buy a MS SQL book also, I guess that the DefinedSize comes from MS SQL properties.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On