For years I have been working with MS Access and enjoying the simplicity and ease of use. I am now making the move and converting all of my sites to MSSQL. Virtually everything works but in the process, I have found an oddity that I am not used to.
I have a question about fields in an MSSQL DB or any type of SQL DB for that matter. My question concerns pulling data from fields out of a particular order.
Let’s say that you have a table with the following fields in their specific order:
tblMyTable:
fld_id
fld _name
fld _email
fld_ip
Using ASP/VBScript I can access the data by connecting to the correct MSSQL server. I can display the information with no problems unless I attempt to pull the information out of order. For instance if I want to display the fld_ip and then the fld_name it will not work. Only fld_ip would be displayed. I presume that this is because fld_name comes BEFORE fld_ip.
SQL Statement: "SELECT * FROM tblMyTable"
Code Examples:
In this example, I am calling the fields in the order in which they appear in the table. Both items display correctly.
<table>
<tr>
<td>ID:</td>
<td><%=(rsRecordset.Fields.Item("fld_id").Value)%></td>
</tr>
<tr>
<td>Name:</td>
<td><%=(rsRecordset.Fields.Item("fld_name").Value)%></td>
</tr>
<tr>
<td>Email:</td>
<td><%=(rsRecordset.Fields.Item("fld_email").Value)%></td>
</tr>
<tr>
<td>IP:</td>
<td><%=(rsRecordset.Fields.Item("fld_ip").Value)%></td>
</tr>
</table>
In this example, I am calling the fields out of order. Only fld_ip displays correctly. fld_name does not display at all again I presume that this is because fld_name comes BEFORE fld_ip.
<table>
<tr>
<td>ID:</td>
<td><%=(rsRecordset.Fields.Item("fld_id").Value)%></td>
</tr>
<tr>
<td>IP:</td>
<td><%=(rsRecordset.Fields.Item("fld_ip").Value)%></td>
</tr>
<tr>
<td>Name:</td>
<td><%=(rsRecordset.Fields.Item("fld_name").Value)%></td>
</tr>
<tr>
<td>Email:</td>
<td><%=(rsRecordset.Fields.Item("fld_email").Value)%></td>
</tr>
</table>
In addition to this, I am not able to display fields more than once.
<table>
<tr>
<td>ID:</td>
<td><%=(rsRecordset.Fields.Item("fld_id").Value)%></td>
</tr>
<tr>
<td>Name:</td>
<td><%=(rsRecordset.Fields.Item("fld_name").Value)%></td>
</tr>
<tr>
<td>Email:</td>
<td><%=(rsRecordset.Fields.Item("fld_email").Value)%></td>
</tr>
<tr>
<td>IP:</td>
<td><%=(rsRecordset.Fields.Item("fld_ip").Value)%></td>
</tr>
<tr>
<td>Name:</td>
<td><%=(rsRecordset.Fields.Item("fld_name").Value)%></td>
</tr>
</table>
The second instance of the field “fld_name” will not display at all.
With MS Access I could display the data in any order I wanted. I could also display them multiple times without any problems.
The BIG QUESTION… Why on Earth would MSSQL behave this way?
Now, I realize that I could easily assign the data to variables and use them any way I wanted to like this:
<%
varID = (rsRecordset.Fields.Item("fld_id").Value)
varName = (rsRecordset.Fields.Item("fld_name").Value)
varEmail = (rsRecordset.Fields.Item("fld_email").Value)
varIP = (rsRecordset.Fields.Item("fld_ip").Value)
%>
That’s great but not necessarily the most efficient way to reduce code.
So what is the deal with the limitation on this more advanced DB? What am I missing?
Thanks!
Dean