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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid not displaying results??

Status
Not open for further replies.

CJAI

MIS
Oct 21, 2003
224
US
When the page loads I get no errors, but nothing displays to the screen - please help as I am an extreme newbie to dot net.

Code:
Protected Sub Page_Load
'Get date and time to display to screen
Dim dtNow As DateTime = DateTime.Now
DisplayDate.text = dtNow.ToString( "D" )
		
'Query tbl_TraverTracker in Intranet DB on ESSPITSRV01 and bind data to 
'label AllTrips
Dim myConn AS New SQLConnection("SERVER=esspitsrv01;DATABASE=intranet;UID=sa;PWD=PRD$3PES$;")
myConn.Open
		
Dim strSql AS String = "SELECT * FROM tbl_TravelTracker ORDER BY TripNumber"
Dim myCommand AS New SQLCommand(strSQL, myConn)
		
Dim myDataReader AS SQLDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
		
'Bind Data
AllTrips.DataSource = myDataReader
AllTrips.DataBind
		
MyConn.close()
		
End Sub

Datagrid
Code:
<form id="mainForm" runat="server">
<asp:DataGrid id="AllTrips" runat="server" AutoGenerateColumns="False" EnableViewSate="True"
width="100%">
<columns>
<asp:BoundColumn DataField="TripNumber" HeaderText="Trip #" />
<asp:BoundColumn DataField="ProjectID" HeaderText="Project" />
<asp:BoundColumn DataField="StartDate" HeaderText="Start Date" />
<asp:BoundColumn DataField="EndDate" HeaderText="End Date" />
<asp:BoundColumn DataField="DestinationCity" HeaderText="Destination" />
<asp:BoundColumn DataField="Invoiced" HeaderText="Invoice #" />
</columns>
</asp:DataGrid>
</form>

I've been beating my head in here for an hour - any help is highly appreciated!!
 
Not sure if this will do it...

Code:
if not page.ispostback then
 Dim dtNow As DateTime = DateTime.Now
 DisplayDate.text = dtNow.ToString( "D" )
        
 'Query tbl_TraverTracker in Intranet DB on ESSPITSRV01  and bind data to 
 'label AllTrips
 Dim myConn AS New SQLConnection ("SERVER=esspitsrv01;DATABASE=intranet;UID=sa;PWD=PRD$3PES$;")
 myConn.Open
        
 Dim strSql AS String = "SELECT * FROM tbl_TravelTracker ORDER BY TripNumber"
 Dim myCommand AS New SQLCommand(strSQL, myConn)
        
 Dim myDataReader AS SQLDataReader =  myCommand.ExecuteReader(CommandBehavior.CloseConnection)
        
 'Bind Data
 AllTrips.DataSource = myDataReader
 AllTrips.DataBind
        
 MyConn.close()
end if
 
Im getting an error now that says

"BC30451: Name 'AllTrips' is not declared."

And all trips is a datagrid so I have no clue why I am getting the error.
 
I didn't know that VB.Net let you get away with this:
AllTrips.DataBind

Shouldn't it be AllTrips.DataBind[red]()[/red]?
 
parantheses after a function name are not mandatory in VB.NET

the problem might be that you're binding directly to a datareader.

try
Code:
if not page.ispostback then
 Dim dtNow As DateTime = DateTime.Now
 DisplayDate.text = dtNow.ToString( "D" )
        
 'Query tbl_TraverTracker in Intranet DB on ESSPITSRV01  and bind data to 
 'label AllTrips
 Dim myConn AS New SQLConnection ("SERVER=esspitsrv01;DATABASE=intranet;UID=sa;PWD=PRD$3PES$;")
 myConn.Open
        
 Dim strSql AS String = "SELECT * FROM tbl_TravelTracker ORDER BY TripNumber"
 Dim myCommand AS New SQLCommand(strSQL, myConn)
        
 Dim myDataAdapter AS SqlDataAdapter =  new SqlDataAdapter(myCommand)
 Dim dt AS DataTable = new DataTable()
 myDataAdapter.Fill (dt)
        
 'Bind Data
 AllTrips.DataSource = dt
 AllTrips.DataBind
        
 MyConn.close()
end if

--------------------------
"two wrongs don't make a right, but three lefts do" - the unknown sage
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top