473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

HELP!

I am having a problem with a datagrid I am trying to use. I have an Access
DB with two records I want to display. All that is displayed is the heading
for the datagrid. I can't seem to display the actual data.

Below is the Code Behind Portion:

Imports System.Data.OleDb

Public Class Units
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents UnitList As System.Web.UI.WebControls.DataGrid
Protected WithEvents UnitLists As System.Web.UI.WebControls.DataGrid

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
BindDataGrid()
End Sub

Sub BindDataGrid()
Dim strSQL As String = "SELECT * FROM Unit_General"
Dim dbconn As New
OleDb.OleDbConnection(System.Configuration.Configu rationSettings.AppSettings.Get("dsn"))
Dim dt As DataTable
Dim dr As DataRow
Dim dret As OleDb.OleDbDataReader
Dim i As Integer

dbconn.Open()
Dim Command As New OleDb.OleDbCommand(strSQL, dbconn)
dret = Command.ExecuteReader(CommandBehavior.CloseConnect ion)

Try
'create a DataTable
dt = New DataTable
dt.Columns.Add(New DataColumn("Unit Number", GetType(Integer)))
dt.Columns.Add(New DataColumn("Price", GetType(Double)))
dt.Columns.Add(New DataColumn("SqFt", GetType(String)))
dt.Columns.Add(New DataColumn("Floor Plan", GetType(String)))
dt.Columns.Add(New DataColumn("Tenant Status", GetType(String)))
dt.Columns.Add(New DataColumn("Beds", GetType(Integer)))
dt.Columns.Add(New DataColumn("Baths", GetType(Integer)))

Do While dret.Read()
dr = dt.NewRow()
dr(0) = dret(13)
dr(1) = dret(2)
dr(2) = dret(3)
dr(3) = dret(4)
dr(4) = dret(9)
dr(5) = dret(6)
dr(6) = dret(7)

'add the row to the datatable
dt.Rows.Add(dr)
Loop

Catch
End Try

dbconn.Close()
Command.Connection.Close()

'return a DataView to the DataTable
UnitLists.DataSource = New DataView(dt)
UnitLists.DataBind()

End Sub
End Class

THE ASPX REFERENCE TO THE DATAGRID IS AS FOLLOWS:

<asp:datagrid id="UnitLists" runat="server" ForeColor="Black"
GridLines="Horizontal" CellPadding="4"
BackColor="White" BorderWidth="1px" BorderStyle="None"
BorderColor="#CCCCCC" Width="696px"
DataKeyField="Unit Number" AutoGenerateColumns="False"
EditItemStyle-BackColor="yellow" PageSize="50"
AllowSorting="True">
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#CC3333"></SelectedItemStyle>
<EditItemStyle BackColor="Yellow"></EditItemStyle>
<AlternatingItemStyle BackColor="#E0E0E0"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#333333"></HeaderStyle>
<FooterStyle ForeColor="Black" BackColor="#CCCC99"></FooterStyle>
<Columns>
<asp:BoundColumn DataField="Unit Number" ReadOnly="True"
HeaderText="Unit Number"></asp:BoundColumn>
<asp:BoundColumn DataField="Price" ReadOnly="True"
HeaderText="Price"></asp:BoundColumn>
<asp:BoundColumn DataField="SqFt" ReadOnly="True"
HeaderText="SqFt"></asp:BoundColumn>
<asp:BoundColumn DataField="Floor Plan" ReadOnly="True"
HeaderText="Floor Plan"></asp:BoundColumn>
<asp:BoundColumn DataField="Tenant Status" ReadOnly="True"
HeaderText="Tenant Status"></asp:BoundColumn>
<asp:BoundColumn DataField="Beds" ReadOnly="True"
HeaderText="Beds"></asp:BoundColumn>
<asp:BoundColumn DataField="Baths" ReadOnly="True"
HeaderText="Baths"></asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="Right" ForeColor="Black"
BackColor="White"></PagerStyle>
</asp:datagrid>
Any help is greatly appreciated!

Sincerely,
ryan

Nov 19 '05 #1
6 1354
Any Errors specifically?
*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #2
"Ryan Smith" <Ry*******@discussions.microsoft.com> wrote in message
news:2F**********************************@microsof t.com...
dret = Command.ExecuteReader(CommandBehavior.CloseConnect ion)


So, does this actually contain any rows of data...?
Nov 19 '05 #3
No errors - the header shows but no data...

"Patrick Olurotimi Ige" wrote:
Any Errors specifically?
*** Sent via Developersdex http://www.developersdex.com ***

Nov 19 '05 #4
Yes - the table in the db has two rows...

"Mark Rae" wrote:
"Ryan Smith" <Ry*******@discussions.microsoft.com> wrote in message
news:2F**********************************@microsof t.com...
dret = Command.ExecuteReader(CommandBehavior.CloseConnect ion)


So, does this actually contain any rows of data...?

Nov 19 '05 #5
"Ryan Smith" <Ry*******@discussions.microsoft.com> wrote in message
news:33**********************************@microsof t.com...
Yes - the table in the db has two rows...
That isn't what I asked... I asked if the DataReader object contained any
rows of data...
"Mark Rae" wrote:
"Ryan Smith" <Ry*******@discussions.microsoft.com> wrote in message
news:2F**********************************@microsof t.com...
> dret = Command.ExecuteReader(CommandBehavior.CloseConnect ion)


So, does this actually contain any rows of data...?

Nov 19 '05 #6
Having a quick glance at ur code i guess maybe its becos u are closing
the ExecuteReader connection before adding/creating the Datatabe

I was also thinking u didn't set AutoGenerateColumns = true in ur
DataGrid but u don't need it as u explicitly specify what columns should
appear in the DataGrid via BoundColumns.

Patrick

*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
9
by: Tom | last post by:
A question for gui application programmers. . . I 've got some GUI programs, written in Python/wxPython, and I've got a help button and a help menu item. Also, I've got a compiled file made with...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
7
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
5
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
1
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
0
by: hitencontractor | last post by:
I am working on .NET Version 2003 making an SDI application that calls MS Excel 2003. I added a menu item called "MyApp Help" in the end of the menu bar to show Help-> About. The application...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.