Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

No Rows Display In Datagrid 1

Status
Not open for further replies.

wtmckown

Programmer
Mar 19, 2003
121
0
0
US
I am having trouble binding a dataset table to a datagrid control. Here's the code that yields no rows in the grid. I'm sure that the dataset table contains data.
'---------------------------------------------
strSQL = "SELECT tblBudget.lID, tblBudget.iMonth, tblBudget.lPounds, " _
& "tblBudget.cProcessing, tblBudget.cReplacement, tblBudget.lPWU, " _
& "tblBudget.lSWU, tblBudget.lTWU FROM tblBudget " _
& " WHERE tblBudget.iYear = " & ddlYear.SelectedItem.Value _
& " And tblBudget.iFacilityNumber = " & ddlFacility.SelectedItem.Value _
& " And tblBudget.iLocationNumber = " & ddlLocation.SelectedItem.Value _
& " ORDER BY tblBudget.iMonth;"

Dim conLaundry As New OleDbConnection(Application("sLCSConnectionString"))
Dim cmdlaundry As New OleDbCommand(strSQL, conLaundry)
Dim daLaundry As New OleDbDataAdapter(cmdlaundry)
Dim dsLaundry As New DataSet
Dim dgBudget As New DataGrid
daLaundry.Fill(dsLaundry, "Budget")


dgBudget.DataSource = dsLaundry.Tables("Budget")
dgBudget.DataBind()
'-------------------------------

Any ideas?
 
Check you sql statement. do a response.write strsQL to make sure the syntax is correct and that it is formed the way you are expecting. If it looks right, run the query outside of .NET and make sure you are pulling rows.

Jim
 
If I use that exact same sql stmt with a datareader then I can bind it successfully to the grid:

'--------------------------
Dim conLaundry As OleDbConnection
Dim cmdLaundry As OleDbCommand
Dim rdrLaundry As OleDbDataReader

conLaundry = New OleDbConnection(Application("sLCSConnectionString"))
conLaundry.Open()

strSQL = "SELECT tblBudget.lID, tblBudget.iMonth, tblBudget.lPounds, " _
& "tblBudget.cProcessing, tblBudget.cReplacement, tblBudget.lPWU, " _
& "tblBudget.lSWU, tblBudget.lTWU FROM tblBudget " _
& " WHERE tblBudget.iYear = " & ddlYear.SelectedItem.Value _
& " And tblBudget.iFacilityNumber = " & ddlFacility.SelectedItem.Value _
& " And tblBudget.iLocationNumber = " & ddlLocation.SelectedItem.Value _
& " ORDER BY tblBudget.iMonth;"


cmdLaundry = New OleDbCommand(strSQL, conLaundry)

rdrLaundry = cmdLaundry.ExecuteReader
dgBudget.DataSource = rdrLaundry
dgBudget.DataBind()

rdrLaundry.Close()
cmdLaundry.Dispose()
conLaundry.Close()
'--------------------------


That works fine. I also am able to step the dataset table as a test to make sure that there are rows. I just can't get the rows to display in the grid. I'm posting the grid def here just in casr I'm blowing something there.

'------------------------------

<asp:DataGrid ID="dgBudget" runat="server" BorderWidth ="1"
CellSpacing="1" CellPadding ="1" AutoGenerateColumns =false
AllowSorting=true Width="490" DataKeyField="lID"
ShowFooter="True" FooterStyle-HorizontalAlign ="right"
FooterStyle-Font-Size ="XX-Small" FooterStyle-Font-Bold ="true" >
<HeaderStyle BackColor=Cyan ForeColor="White" Font-Bold="True"
HorizontalAlign="Center" Font-Size="10" />
<AlternatingItemStyle BackColor=lightBlue />
<Columns>
<asp:BoundColumn DataField="lID" Visible="false" />
<asp:BoundColumn HeaderText="Month" HeaderStyle-HorizontalAlign="center" DataField="iMonth"
ItemStyle-HorizontalAlign ="Left" ItemStyle-Font-Size="XX-Small" ItemStyle-VerticalAlign ="top" />
<asp:BoundColumn HeaderText="Pounds" HeaderStyle-HorizontalAlign="center" DataField="lPounds"
ItemStyle-HorizontalAlign ="right" ItemStyle-Font-Size="XX-Small" ItemStyle-VerticalAlign ="top" />
<asp:BoundColumn HeaderText="Processing" DataFormatString ="{0:C2}" HeaderStyle-HorizontalAlign="center" DataField="cProcessing"
ItemStyle-HorizontalAlign ="right" ItemStyle-Font-Size="XX-Small" ItemStyle-VerticalAlign ="top" />
<asp:BoundColumn HeaderText="Replacement" DataFormatString ="{0:C2}" HeaderStyle-HorizontalAlign="center" DataField="cReplacement"
ItemStyle-HorizontalAlign ="right" ItemStyle-Font-Size="XX-Small" ItemStyle-VerticalAlign ="top" />
<asp:BoundColumn HeaderText="PWU" HeaderStyle-HorizontalAlign="center" DataField="lPWU"
ItemStyle-HorizontalAlign ="right" ItemStyle-Font-Size="XX-Small" ItemStyle-VerticalAlign ="top" />
<asp:BoundColumn HeaderText="SWU" HeaderStyle-HorizontalAlign="center" DataField="lSWU"
ItemStyle-HorizontalAlign ="right" ItemStyle-Font-Size="XX-Small" ItemStyle-VerticalAlign ="top" />
<asp:BoundColumn HeaderText="TWU" HeaderStyle-HorizontalAlign="center" DataField="lTWU"
ItemStyle-HorizontalAlign ="right" ItemStyle-Font-Size="XX-Small" ItemStyle-VerticalAlign ="top" />
</Columns>
</asp:DataGrid>
'------------------------------
 
You have this line:
Code:
Dim dgBudget As New DataGrid

Why? do you plan on adding the grid dynamically to the page? If you have dragged and dropped the grid already, then remove that line.
 
Good question....No good answer why I have that statement....removing it fixes problem....Thanks.
 
No problem...Basically it was overriding the existing dg. I would have expected a compilation error...

Glad you got it..

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top