Great Example of MDB Tomtt, But it didn't wor

useri

New Member
Ok,<BR><BR>I created the table just as you told me (File Name: Test.mdb; Table name: TestTable and Top Fields Names: rID -autonumber-, rDate -date-, rName -text- and rScore -number- ).<BR><BR>Then I copy and paste your code, and modify it just to view the data wich I had put on the Access table but the only result that I get is a Blank Page :-( , at least asp.net don't report any errors so I think this is probably a little Error...<BR><BR>This is the little code I used:<BR><BR>----------------------------<BR><BR><%@ Page Language="VB" %> <BR><%@ Import NameSpace="System.Data" %> <BR><%@ Import NameSpace="System.Data.OleDb" %> <BR><BR><SCRIPT RUNAT="SERVER"><BR><BR>sub Page_Load(obj as Object, e as EventArgs) <BR><BR>' CREATE OBJECTS, OPEN DB, LOAD DATASET, LOAD DATA GRID. <BR>' CREATE DATASET AND ADD NEW DATATABLE TO IT. <BR><BR> Dim objDSet As New DataSet <BR> Dim tblTest As DataTable = objDSet.Tables.Add("tblTest") <BR><BR>' CREATE CONNECTION STRING AND SELECT COMMAND. <BR><BR>Dim objConn As New oleDBConnection ("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:InetPubwwwrootTest.mdb") <BR><BR>Dim objSelect As New oleDBCommand("SELECT * FROM TestTable ORDER BY rDate DESC", objConn)<BR><BR>' Should I put a "objDGrid.DataBind()" here? aniway it doesn't work...<BR><BR>End sub <BR><BR></SCRIPT> <BR><BR><!-- ============= HTML PAGE STARTS HERE ================--> <BR><BR><HTML><BODY> <BR><BR> <BR/><BR/> <BR><BR> <ASP:DataGrid id="objDGrid" <BR>align="Center" <BR>runat="Server" <BR>Width = "400" <BR><BR>BorderColor="Black" <BR>BackColor="#ffffff" <BR>CellPadding=3 <BR>CellSpacing="0" <BR>Font-Name="Verdana" AllowSorting="False" <BR>Font-Size="8pt" <BR>HeaderStyle-BackColor="#cfcfcf" <BR>enableViewState="false" /> <BR><BR></BODY></HTML> <BR><BR>----------------------------<BR><BR>Hope somebody can localice the error, aniway Thanks a lot for this code Tomtt ;-)<BR><BR>Sorry again for my pour english grammar, and thanks for your time.<BR><BR>From Spain:<BR>Salvador Gallego.Thanks aniway for those who answered to my post before. I hope I can work now more fluently after have the access to the data!.<BR><BR>After try with one thousand of examples, and post 7 times to diferent forums places, the simple code I was searching is the following:<BR><BR>---------------------<BR><%@ Import Namespace="System.Data.OLEDB" %><BR><BR><script language="VB" runat="server"><BR>Sub Page_Load(Src As Object, E As EventArgs)<BR> Dim strConn as string ="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & server.mappath("/Test.mdb") & ";" <BR> Dim strSQL as string ="select * from TestTable"<BR> Dim Conn as New OLEDBConnection(strConn)<BR> Dim Cmd as New OLEDBCommand(strSQL,Conn)<BR> Conn.Open()<BR> myDataGrid.DataSource = Cmd.ExecuteReader(system.data.CommandBehavior.Clos eConnection)<BR> myDataGrid.DataBind()<BR>End Sub<BR></script><BR><html><head><BR><title>Mis datos</title><BR></head><BR><body bgcolor="#FFFFFF"><BR><font face="Verdana"><h3>La tabla resultado, es esta: </h3></font><BR><ASP:DataGrid id="MyDataGrid" runat="server"<BR> Width="100%"<BR> BackColor="white" <BR> BorderColor="black"<BR> ShowFooter="false" <BR> CellPadding=3 <BR> CellSpacing="0"<BR> Font-Name="Verdana"<BR> Font-Size="8pt"<BR> Headerstyle-BackColor="lightblue"<BR> Headerstyle-Font-Size="10pt"<BR> Headerstyle-Font-Style="bold"<BR> MaintainState="false"<BR>/><BR></body></html><BR>---------------------<BR><BR>This realy works and I know that is very simple, but I really didn't be able to found it anywhere...<BR>Well, hope it can be useful to somebody;<BR><BR>From Spain:<BR>Salvador Gallego.<%@ Page Language="VB" %><BR><%@ Import Namespace="System.Data" %><BR><%@ Import Namespace="System.Data.OleDb" %><BR><BR><script runat="server"><BR>Sub Page_Load(Sender as Object, E as EventArgs)<BR><BR>'Set up connection<BR>Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:inetpubwwwroot est.mdb")<BR><BR>'Open Connection<BR>Dim objCmd As New OLEDbDataAdapter("Select * FROM TestTable ORDER BY rDate DESC", objConn)<BR><BR>'Fill Dataset<BR>Dim ds As DataSet = new DataSet()<BR>objCmd.Fill(ds, "TestTable")<BR><BR>MyDataGrid.DataSource = ds.Tables("TestTable").DefaultView<BR>MyDataGrid.DataBind()<BR>End Sub<BR></script><BR><BR><html><BR><BR><body><BR><form runat="server"><BR><BR><ASP:DataGrid id="MyDataGrid" runat="server"<BR>BorderColor="black"<BR>GridLines="vertical"<BR>Cellpadding="4"<BR>Cellspacing="0"<BR>Width="450"<BR>Font-Names="Arial"<BR>Font-Size="8pt"<BR>ShowFooter="True"<BR>HeaderStyle-BackColor="#CCCC99"<BR>FooterStyle-BackColor="#CCCC99"<BR>ItemStyle-BackColor="#FFFFFF"<BR>AlternatingItemStyle-BackColor="#CCCCCC"<BR>AutoGenerateColumns="False"><BR><BR><Columns><BR><asp:BoundColumn HeaderText="ID" DataField="rID"/><BR><asp:BoundColumn HeaderText="Date" DataField="rDate"/><BR><asp:BoundColumn HeaderText="Name" DataField="rName"/><BR><asp:BoundColumn HeaderText="Score" DataField="rScore"/><BR></Columns><BR></ASP:DataGrid><BR><BR></form><BR></body><BR></html><%@ Page Language="VB" %><BR><%@ Import Namespace="System.Data" %><BR><%@ Import Namespace="System.Data.OleDb" %><BR><BR><script runat="server"><BR>Sub Page_Load(Sender as Object, E as EventArgs)<BR><BR>'Set up connection<BR>Dim objConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:inetpubwwwroot est.mdb")<BR><BR>'Open Connection<BR>Dim objCmd As New OLEDbDataAdapter("Select * FROM TestTable ORDER BY rDate DESC", objConn)<BR><BR>'Fill Dataset<BR>Dim ds As DataSet = new DataSet()<BR>objCmd.Fill(ds, "TestTable")<BR><BR>MyDataGrid.DataSource = ds.Tables("TestTable").DefaultView<BR>MyDataGrid.DataBind()<BR>End Sub<BR></script><BR><BR><html><BR><BR><body><BR><form runat="server"><BR><BR><ASP:DataGrid id="MyDataGrid" runat="server"<BR>BorderColor="black"<BR>GridLines="vertical"<BR>Cellpadding="4"<BR>Cellspacing="0"<BR>Width="450"<BR>Font-Names="Arial"<BR>Font-Size="8pt"<BR>HeaderStyle-BackColor="#CCCC99"<BR>ItemStyle-BackColor="#FFFFFF"<BR>AlternatingItemStyle-BackColor="#CCCCCC"<BR>AutoGenerateColumns="False"><BR><BR><Columns><BR><asp:BoundColumn HeaderText="ID" DataField="rID"/><BR><asp:BoundColumn HeaderText="Date" DataField="rDate"/><BR><asp:BoundColumn HeaderText="Name" DataField="rName"/><BR><asp:BoundColumn HeaderText="Score" DataField="rScore"/><BR></Columns><BR></ASP:DataGrid><BR><BR></form><BR></body><BR></html>Salvador, <BR>Sorry for not responding sooner (server down).<BR><BR>I looked at the code you posted, to see why it would not work since the example I sent was straight from a working file. Looks like maybe you didn't copy all of the file from the messageboard.<BR><BR>Anyway, I see you are using a datareader to do the same thing and have it working.<BR><BR>Good luck with your coding.<BR><BR>TomT
 
Back
Top