Display Datagrid using MS Access database

  • Thread starter Thread starter daudihus
  • Start date Start date
D

daudihus

Hi there,
I followed the VS.NET walkthrough on creating a Paged Data Access
Application step by step. The problem is that the Datagrid does not
display at all. I only see two link buttons (Previous and Next) and
nothing else. I've tried to code the entire application for scratch
(following other examples) but still the same result.
I'm running IIS on XP SP3 with Access 2003.

BTW everything works fine when I run the same app on my Windows server
2003 machine.

Any help is greatly appreciated.

Cheers,

Daudi
 
Daudihus,

This is an almost impible to answer question from a newsgroup.

However we can give it a try if you show us the code that should get the
data and fill the datasource.

Cor
 
Hi Everyone,
Sorry if I wasn't too clear with my original post. Anyway here's the
code that works on my windows server 2003 machine but not on XP.
I strongly believe that the problem lies somewhere with IIS.

To the code:
The Webform contains:
- two asp linkbutton controls (btnNext and btnPrevious) for navigating
the datagrid
- a datagrid (datagrid1)
- two asp labels (lblStones and lblCarats) for displaying data from the
database

The datasource for the datagrid is a stored procedure (access query).
Here's the sql:

SELECT TOP 10 qryExportDetails.RECEIPTNUM, qryExportDetails.RECEIPTDATE,
qryExportDetails.STONES, qryExportDetails.CARATS,
qryExportDetails.ROYALTIES
FROM qryExportDetails
WHERE (((qryExportDetails.RECEIPTNUM)>[@receiptnum]) AND
((qryExportDetails.exportID)=40))
ORDER BY qryExportDetails.RECEIPTNUM;



Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class WebForm1
Inherits System.Web.UI.Page
Private CurrentPage As Integer
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents btnPrevious As
System.Web.UI.WebControls.LinkButton
Protected WithEvents btnNext As System.Web.UI.WebControls.LinkButton


Private connString As String =
"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=D:\OFFICE_DATA\SAMI\2005\exports 2005\ems 05 may 2005.mdb"


And the code for the WebForm:

Protected WithEvents lblCarats As System.Web.UI.WebControls.Label
Protected WithEvents lblStones As System.Web.UI.WebControls.Label
Private objConn As New OleDbConnection(connString)



Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not Page.IsPostBack Then
Dim objCmdNext As New OleDbCommand("spNextExportsDetails",
objConn)
Dim objParam As New OleDbParameter("@receiptnum",
OleDbType.BSTR)
objCmdNext.CommandType = CommandType.StoredProcedure
objParam.Value = ""
objCmdNext.Parameters.Add(objParam)

Try

FillGridODB(objCmdNext)

Dim strSQLExport As String = "select WeightCts, Stones
from tblExports where exportID = 40"
Dim objCmdExport As New OleDb.OleDbCommand(strSQLExport,
objConn)
objCmdExport.CommandType = CommandType.Text
objConn.Open()
Dim drExport As OleDb.OleDbDataReader =
objCmdExport.ExecuteReader

While drExport.Read
lblCarats.Text = drExport.GetValue(0)
lblstones.Text = drExport.GetValue(1)

End While
drExport.Close()
objConn.Close()

Catch ee As Exception
Throw ee
End Try

End If

End Sub



Private Sub FillGridODB(ByVal currentODBCommand As
OleDb.OleDbCommand)
Dim dr As OleDb.OleDbDataReader
objConn.Open()
dr = currentODBCommand.ExecuteReader()
DataGrid1.DataSource = dr
DataGrid1.DataBind()
dr.Close()
objConn.Close()


ViewState("CurrentPage") = CurrentPage
viewstate(CurrentPage.ToString) =
DataGrid1.Items(0).Cells(0).Text
If DataGrid1.Items.Count < DataGrid1.PageSize Then
btnNext.Enabled = False
End If

End Sub

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnNext.Click
CurrentPage = CType(viewstate("CurrentPage"), Integer)
CurrentPage += 1

Dim objCmdNext As New OleDbCommand("spNextExportsDetails",
objConn)
Dim objParam As New OleDbParameter("@receiptnum",
OleDbType.BSTR)
objCmdNext.CommandType = CommandType.StoredProcedure

Dim lastid As String = DataGrid1.Items(9).Cells(0).Text
objParam.Value = lastid
objCmdNext.Parameters.Add(objParam)

FillGridODB(objCmdNext)
End Sub

End Class
 
Daudi,

I was asking my previous question to see if there was something as this in
your code and I hope that I did not oversee it.
Catch ee As Exception
Throw ee
End Try
What is that "ee" doing? My expection is that it just end the program as
that is in webpages normal when it is unresolvable.

Cor
 
Cor,
I'm not sure why that bit of code is there? Are u suggesting I take it
out?
I merely followed the visual studio walkthrough called
"Creating a Web Application Using Visual C# or Visual Basic"

On my system it's found at
ms-help://MS.VSCC/MS.MSDNVS/vsintro7/html/vxwlkWalkthroughCreatingWebApplicationUsingVisualCOrVisualBasic.htm

I replaced all the references to Sql (like SqlConnection1) with OleDB
(like OleDBConnection1)

Anyway, the real question is why would it work on a windows server 2003
machine and not on a windows xp pro machine? Both are running IIS.
Do I need something like Frontpage Server Extension?

Thanks

Daudi
 
Daudi,
Anyway, the real question is why would it work on a windows server 2003
machine and not on a windows xp pro machine? Both are running IIS.
Do I need something like Frontpage Server Extension?
Did you take it out, or better replace it by something as
catch ex as exception
response.write(ex)

I expect that there is something as an IO error that stops the processing,
however you don't see it now because it is now catched by a catch, which
does than show nothing, and therefore the error is passed (and your datagrid
not filled).

Cor
 
Cor,
I tried running the app with the database open (should create an access
violation). Same result. seems like the oledbconnection is not working.

Daudi
 
Ok, so it seems like the whole ASP.NET thing is not working. I inserted

Response.write("HEllo world") into the page load and still nothing. So
I'm reinstalling the whole VS.NET.
 
So finally it worked...
After reinstalling it still didn't solve the problem. Then I stumbled
across a little command called "aspnet_regiis.exe" (run from command
prompt). That seemed to be the problem. Aparently my asp.net was never
registered with IIS.

So thanks again for the help.

BTW.. I also need help putting subtotals in a datagrid using MS Access
(will post). None of the examples that I've seen so far seem to work.

Regards,
Daudi
 
Back
Top