Non-Collapsible Repeater Demo

This Repeater shows a lot of data per record, making the page unwieldy.


How do you convert a string to all uppercase or all lowercase?


Submitted By: Scott Mitchell
Views: 53397
FAQ:
To convert a string to uppercase use the UCase function. To convert a string to lowercase use the LCase function.

Dim str
str = "ThIs iS a sTRInG wITh mIxED casE."

'This will print out the string all in lowercase
Response.Write LCase(str)

'This will print out the string all in uppercase
Response.Write UCase(str)

How do you create a database table through a SQL statement (via an ASP page, perhaps)?


Submitted By: Scott Mitchell
Views: 74803
FAQ:
To create a database table, use the SQL command CREATE TABLE. The command is pretty complex, and before you start creating tables via SQL code, be sure to read up on the command in the SQL Books On-Line. The basic structure of the CREATE TABLE statement is as follows:

CREATE TABLE TableName
(
   ColumnName1 Datatype Properties
   ColumnName2 Datatype Properties
  ...
   ColumnNameN Datatype Properties
)

So, to create a table named FooBar with Name and Age columns, you could use the following SQL script:

CREATE TABLE FooBar
(
  Name varchar(50),
  Age int
)

To view a short example on how to accomplish this through an ASP page, take a moment to read this ASPMessageboard post!

The above example works well for creating a database table... but what if you want to create, say, an entire Access database (including the .MDB file itself)? Fortunately Microsoft has provided a set of libraries referred to as ADOX which allow for this functionality. To learn more about ADOX be sure to read: Working with ADOX.

Happy Programming!

How do I dynamically resize an array?


Submitted By: Scott Mitchell
Views: 71897
FAQ:
An array can be resized with the Redim statement. The Redim statement takes the following form:

Redim [Preserve] varname(subscripts)

The Preserve should be used if your array contains information that you do not wish to lose when you resize the array. However, if you use the Preserve keyword you can only resize the last dimension of the array; furthermore, use of the Preserve keyword prevents you can't from altering the number of dimensions in the array. (Of course the Preserve won't save the excess arrray information if you specify a smaller size than the orginal array.)

An example of using the Redim statement can be seen below:

'MyArray has five elements
Dim MyArray(5)

'Resize MyArray so it has 10 elements
ReDim MyArray(10)

To learn more about Redim, read the technical documents.

How can I tell what version of ADO I am using?


Submitted By: Scott Mitchell
Views: 43809
FAQ:
Use the Version property of the ADODB.Connection object. In this quick and dirty example we'll create a Connection object and print out its Version property:

'Create Connection object
Dim objConn
Set objConn = Server.CreateObject("ADODB.Connection")

'Print out version property
Response.Write("You are using ADO Version " & objConn.Version)

For more information on ADO, visit Microsoft's Universal Data Access site: http://www.microsoft.com/data/.

Or, to go directly to a reference manual for ADO, try this Microsoft site.


Source Code
<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<script language="vb" runat="server">
  'Create a connection
  Dim myConnection as New SqlConnection(ConfigurationSettings.AppSettings("connectionString"))


  Sub Page_Load(sender as Object, e as EventArgs)
    If Not Page.IsPostBack then
      BindData()
    End If
  End Sub

	
  Sub BindData()
    '2. Create the command object, passing in the SQL string
    Const strSQL as String = "SELECT * FROM tblFAQ WHERE FAQID <= 5"

    'Set the datagrid's datasource to the datareader and databind
    Dim resultsDataSet as New DataSet()
    Dim myDataAdapter as SqlDataAdapter = New SqlDataAdapter(strSQL, myConnection) 
    myDataAdapter.Fill(resultsDataSet)   

    rptFAQs.DataSource = resultsDataSet
    rptFAQs.DataBind()
  End Sub
</script>

<asp:Repeater id="rptFAQs" runat="server">
   <ItemTemplate>
     <h2><%# DataBinder.Eval(Container.DataItem, "Description") %></h2><br />
     <b>Submitted By:</b> <%# DataBinder.Eval(Container.DataItem, "SubmittedByName") %><br />
     <b>Views:</b> <%# DataBinder.Eval(Container.DataItem, "ViewCount", "{0:d}") %><br />
     <b>FAQ:</b><br />
     <%# DataBinder.Eval(Container.DataItem, "Answer") %>
   </ItemTemplate>
</asp:Repeater>
	


[Return to the article]