G
Guest
Hi,
I have an asp.net script that connects to MS Access database and displays
data in a table. For some reason I am do not know how to display data say in
ascending order of column1.
I have pasted below the script that I am using. I will appreciate if someone
can give me a clue as how to sort data in ascending or descending order when
displaying on the page.
Thanks,
Joe
<%@ page language="VB" debug="true" %>
<%@ Import Column1space="System.Data" %>
<%@ Import Column1space="System.Data.OleDb" %>
<script language="VB" runat="server">
sub Page_Load(sender as Object, e as EventArgs)
Dim connString as String
Dim pathStr As String
pathStr = Left(Request.PhysicalApplicationPath, 10)
connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" & pathStr & "\databases\somedatabase.mdb"
Dim objConnection as OleDbConnection
objConnection = New OleDbConnection(connString)
objConnection.Open()
Dim strSQL as String = "SELECT column1, column2 FROM sometable"
Dim objCommand as OleDbCommand
objCommand = New OleDbCommand(strSQL, objConnection)
Dim objDataReader as OleDbDataReader
objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)
'Set the table width.
DisplayTable.Width = Unit.Percentage(100.0)
'Create a new row for adding a table heading
Dim tableHeading As TableRow = New TableRow()
'Create and add the cells that contain the Customer ID column heading
text.
Dim Column1IDHeading As TableHeaderCell = New TableHeaderCell()
column1IDHeading.Text = "Column1"
column1IDHeading.backcolor =
System.Drawing.Color.FromColumn1(CType("#CCCCCC", String))
column1IDHeading.HorizontalAlign = HorizontalAlign.Center
column1IDHeading.CssClass = "subsubTitle"
tableHeading.Cells.Add(column1IDHeading)
'Create and add the cells that contain the Contact Column1 column
heading text.
Dim companyHeading As TableHeaderCell = New TableHeaderCell()
column2Heading.Text = “column2"
column2Heading.backcolor =
System.Drawing.Color.FromColumn2(CType("#CCCCCC", String))
column2Heading.HorizontalAlign = HorizontalAlign.Center
column2Heading.CssClass = "subsubTitle"
tableHeading.Cells.Add(column2Heading)
DisplayTable.Rows.Add(tableHeading)
'Loop through the resultant data selection and add the data value
'for each respective column in the table.
While(objDataReader.Read())
Dim detailsRow As TableRow = New TableRow()
Dim column1Cell As TableCell = New TableCell()
column1Cell.Text = objDataReader("column1").ToString()
column1Cell.CssClass = "bodyText"
detailsRow.Cells.Add(column1Cell)
Dim companyCell As TableCell = New TableCell()
companyCell.Text = objDataReader("company").ToString()
companyCell.CssClass = "bodyText"
detailsRow.Cells.Add(companyCell)
'Add the new row to the table.
DisplayTable.Rows.Add(detailsRow)
End While
objDataReader.Close()
objConnection.Close()
end sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link href="../styles/basic_cross_plat.css" rel="stylesheet" type="text/css">
</head>
<body>
<a column1="top"></a>
<asp:Table id="DisplayTable" border="1" cellpadding="2" cellspacing="1"
runat="server"></asp:Table>
<p><a href="#top" class="top">top</a></p>
</body>
</html>
I have an asp.net script that connects to MS Access database and displays
data in a table. For some reason I am do not know how to display data say in
ascending order of column1.
I have pasted below the script that I am using. I will appreciate if someone
can give me a clue as how to sort data in ascending or descending order when
displaying on the page.
Thanks,
Joe
<%@ page language="VB" debug="true" %>
<%@ Import Column1space="System.Data" %>
<%@ Import Column1space="System.Data.OleDb" %>
<script language="VB" runat="server">
sub Page_Load(sender as Object, e as EventArgs)
Dim connString as String
Dim pathStr As String
pathStr = Left(Request.PhysicalApplicationPath, 10)
connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" & pathStr & "\databases\somedatabase.mdb"
Dim objConnection as OleDbConnection
objConnection = New OleDbConnection(connString)
objConnection.Open()
Dim strSQL as String = "SELECT column1, column2 FROM sometable"
Dim objCommand as OleDbCommand
objCommand = New OleDbCommand(strSQL, objConnection)
Dim objDataReader as OleDbDataReader
objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)
'Set the table width.
DisplayTable.Width = Unit.Percentage(100.0)
'Create a new row for adding a table heading
Dim tableHeading As TableRow = New TableRow()
'Create and add the cells that contain the Customer ID column heading
text.
Dim Column1IDHeading As TableHeaderCell = New TableHeaderCell()
column1IDHeading.Text = "Column1"
column1IDHeading.backcolor =
System.Drawing.Color.FromColumn1(CType("#CCCCCC", String))
column1IDHeading.HorizontalAlign = HorizontalAlign.Center
column1IDHeading.CssClass = "subsubTitle"
tableHeading.Cells.Add(column1IDHeading)
'Create and add the cells that contain the Contact Column1 column
heading text.
Dim companyHeading As TableHeaderCell = New TableHeaderCell()
column2Heading.Text = “column2"
column2Heading.backcolor =
System.Drawing.Color.FromColumn2(CType("#CCCCCC", String))
column2Heading.HorizontalAlign = HorizontalAlign.Center
column2Heading.CssClass = "subsubTitle"
tableHeading.Cells.Add(column2Heading)
DisplayTable.Rows.Add(tableHeading)
'Loop through the resultant data selection and add the data value
'for each respective column in the table.
While(objDataReader.Read())
Dim detailsRow As TableRow = New TableRow()
Dim column1Cell As TableCell = New TableCell()
column1Cell.Text = objDataReader("column1").ToString()
column1Cell.CssClass = "bodyText"
detailsRow.Cells.Add(column1Cell)
Dim companyCell As TableCell = New TableCell()
companyCell.Text = objDataReader("company").ToString()
companyCell.CssClass = "bodyText"
detailsRow.Cells.Add(companyCell)
'Add the new row to the table.
DisplayTable.Rows.Add(detailsRow)
End While
objDataReader.Close()
objConnection.Close()
end sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link href="../styles/basic_cross_plat.css" rel="stylesheet" type="text/css">
</head>
<body>
<a column1="top"></a>
<asp:Table id="DisplayTable" border="1" cellpadding="2" cellspacing="1"
runat="server"></asp:Table>
<p><a href="#top" class="top">top</a></p>
</body>
</html>