Jump to content

connecting to more than one table


mckenzie
 Share

Recommended Posts

for an example lets take this code that i got from:http://www.powerasp.com/content/code-snipp...p-down-menu.aspif i wanted to connect to a database and populate 18 drop down boxes on an asp page, how would i go about it? can i choose more than one table in the SQL statement to get information from. your probably thinkin what a silly billy aren't u! Dim DataConnDim CmdPopulateStatesDim SQL Set DataConn = Server.CreateObject("ADODB.Connection")Set CmdPopulateStates = Server.CreateObject("ADODB.Recordset")%><% DataConn.Open "DBQ=" & Server.Mappath("_database/zipcodes.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};" SQL = "SELECT DISTINCT STATE_NAME FROM STATES"CmdPopulateStates.Open SQL, DataConn%><form method="POST" action="somepage.asp"><Select Name="STATE_NAME" size="1"><%While Not CmdPopulateStates.EOF%><option value="<%= CmdPopulateStates("STATE_NAME") %>"><%= CmdPopulateStates("STATE_NAME") %></option><%CmdPopulateStates.MoveNextWend CmdPopulateStates.CloseSet CmdPopulateStates = NothingDataConn.CloseSet DataConn = Nothing%></Select><input type="submit" value="Submit"></form>

Link to comment
Share on other sites

You can get data from more than one table at a time but with one single query only. like "select a, b, c from Tbl1 d, Tbl2 e where d.field1 = e.field1"But i think this is not ur requirment.If you want to get data from different tables one for each dropdownthen better use different querries

<%Sub Fill combo (TableName, FieldName)  SQL = "SELECT DISTINCT FieldName FROM TableName"  CmdPopulateStates.Open SQL, DataConn  If Not CmdPopulateStates.EOF Then     Do While Not CmdPopulateStates.EOF          %> <Option value=<%=CmdPopulateStates("FieldName")%>><%=CmdPopulateStates("FieldName")%></Option>         <%         CmdPopulateStates.MoveNext     Loop  End IfCmdPopulateStates.CloseEnd Sub%>

and from html page you can call this Procedure where u want to create dropdown

   <Select Name="Drd1">      <% Call  Fill combo TableName1, FieldName2 %>   </Select>   <Select Name="Drd2">      <% Call  Fill combo TableName2, FieldName2 %>   </Select>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...