ASP, Microsoft SQL and AJAX

1 minute read

Well I haven't done web programming for awhile now and getting back into it was a slow start but I was able to get through it. I'll have to admit, at first Google was my best friend. However, soon I found that the MSDN documentation is actually not too bad if you understand the programming syntax and wording (meaning you're not a total novice at programming).

Many articles can be found online that tell you how to make your first ASP page and connect it to MS SQL, so I'll just summarize the bits that took me the most time:

1. Web.config:
This is a file that is used to house various configurations. I used it to turn off the customErrors so that I could do debugging. The other item I configured here was the connectionStrings - used to create a connection to the database.

<customerrors mode="Off" />
<add name="connName" connectionstring="Data Source=.\SQLEXPRESS;Initial Catalog=dbName;Persist Security Info=True;User ID=sa;Password=password" providername="System.Data.SqlClient" />

2. asp:SqlDataSource:

This is the container used to define your SQL Query. The main item to note with this is the ConnectionString and ProviderName settings. Because we have defined these within the Web.config file, we merely direct the container to retrieve the values from the Web.config file.

<asp:sqldatasource id="generatedDataSource" runat="server" connectionstring="<%$ ConnectionStrings:connName %>" providername="<%$ ConnectionStrings:connName.ProviderName %>" />

3. asp:Panel and asp:DataList:
These two items are the containers for the items that are returned from your SQL Query. I have used the Panel to enclose the DataList in order to enable scrollbars. By default DataList only supports a limited list of formatting options. These can be found in the MSDN documentation as well. However in order to show scrollbars in a pre-defined area a Panel must be used.

<asp:panel runat="server" bordercolor="Black" style="width: 650px; height: 400px; overflow: auto">
<asp:datalist id="generatedDataList" datasourceid="generatedDataSource" onload="CheckClicked" runat="server" repeatcolumns="3">
<itemtemplate><%# Eval("tableCol1") %></itemtemplate>

4. Script generated SQL Query:
The final item that fell in place for my particular project was the script generated SQL Query. I was able to generate the Query from multiple results returned by multiple CheckBoxLists, however in order to re-display the resulting script generated SQL Query I had to set it to the DataList. To do this, assign the sqlDataSource a SelectCommand value.

generatedDataSource.SelectCommand = SQLQuery;

Have fun!

Leave a Comment

Your email address will not be published. Required fields are marked *