473,394 Members | 1,869 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,394 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 1355
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.