chris_angell
01-28-2004, 05:05 PM
hello. I have been trying to work out how to talk to a simple ms access database in asp.net.. in asp it is pretty simple.. but in asp.net I can't work it out...
I am having trouble just talking to the database less alone trying to write to it and display info on my page.... if you could give me some advice on what I am doing wrong I would appriciate it very much ...
here is the code I am using
<%@ Page language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
vb sub
Sub Page_Load(Sender as Object, E as EventArgs)
Dim oConn As OleDbConnection
Dim oComm As OleDbDataAdapter
Dim sConn As String
Dim sComm As String
Dim oDataSet As New DataSet
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
sConn += "Data Source=C:\Inetpub\wwwroot\ImagePhoto\db\russ.mdb;"
sConn += "Persist Security Info=False"
sComm = "SELECT ImageTbl.ImageName, "
sComm += "Products.ImageAlt, "
sComm += "FROM ImageTbl"
oConn = New OleDbConnection(sConn)
oComm = New OleDbDataAdapter(sComm, oConn)
oComm.Fill(oDataSet, "ImageTbl")
oGrid.DataSource=oDataSet.Tables("ImageTbl").DefaultView
oGrid.DataBind()
End Sub
aspx page
<body>
<asp:DataGrid id="oGrid" runat="server" />
</body>
</html>
many thanks chris
:eek:
I am having trouble just talking to the database less alone trying to write to it and display info on my page.... if you could give me some advice on what I am doing wrong I would appriciate it very much ...
here is the code I am using
<%@ Page language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
vb sub
Sub Page_Load(Sender as Object, E as EventArgs)
Dim oConn As OleDbConnection
Dim oComm As OleDbDataAdapter
Dim sConn As String
Dim sComm As String
Dim oDataSet As New DataSet
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
sConn += "Data Source=C:\Inetpub\wwwroot\ImagePhoto\db\russ.mdb;"
sConn += "Persist Security Info=False"
sComm = "SELECT ImageTbl.ImageName, "
sComm += "Products.ImageAlt, "
sComm += "FROM ImageTbl"
oConn = New OleDbConnection(sConn)
oComm = New OleDbDataAdapter(sComm, oConn)
oComm.Fill(oDataSet, "ImageTbl")
oGrid.DataSource=oDataSet.Tables("ImageTbl").DefaultView
oGrid.DataBind()
End Sub
aspx page
<body>
<asp:DataGrid id="oGrid" runat="server" />
</body>
</html>
many thanks chris
:eek: