Click to See Complete Forum and Search --> : DataGrid


RobertSims
06-19-2006, 09:48 AM
The code below uses an MS Access Database. I am attempting to use DataGrids to display the data; however, I think I am not initializing the DataGrids properly. Can someone teach a new dog a new trick?

Thanks!
--Robert

<%@ Page Language="VB" Debug="true" %>
<%@ Import NameSpace="System.Data" %>
<%@ Import NameSpace="System.Data.OleDB" %>

<script runat="server">
sub Page_Load(Sender as object, e as eventargs)
dim objConn as new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=c:\inetpub\wwwroot\intranet2\data\phonelist\phones.mdb")
dim objCmd as new OleDbDataAdapter ("select * from phonelist", objConn)
dim ds as new DataSet
objCmd.Fill(ds, "phonelist")
try
objCmd.Connection.Open()
objReader = objCmd.ExecuteReader
catch ex as OleDbException

end try
DataGrid1.DataSource = ds
DataGrid1.DataBind()
end sub
</script>

lmf232s
06-19-2006, 05:09 PM
Robert,
This is the asp section and you might get better results in the .net section. You might ask one of the mods to move it for you.

Any way, a few things do seem to be out of wack.
You want to put your Databind and Datasource in the Try statment not after.
Also im not sure if you need to actually make a call to open the connection.
I believe this is what the DataAdapter is doing. I could be wrong i just dabble in .net not a guru.

Give this a shot, i'm not sure if this will work or not.

Try
Dim objConn as new OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=c:\inetpub\wwwroot\intranet2\data\phonelist\phones.mdb")
Dim objCmd as new OleDbDataAdapter ("select * from phonelist", objConn)
Dim ds as new DataSet
objCmd.Fill(ds, "phonelist")
DataGrid1.DataSource = ds
DataGrid1.DataBind()
Catch ex As Exception
Response.write(err.Number & " - " & err.Description)
End Try