reading and writing to a database?
-
Ok im new to asp.net and im having trouble trying to populate a label with info from my database. Here is the code i have Imports System.Data.OleDb Module Module1 Public myconn As OleDbConnection Public mycommand As OleDbCommand Public myreader As OleDbDataReader Public gErrorOccurred As Boolean Public p Public strconn As String = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Database Password=;Data Source=D:\Documents and Settings\Tommy's\Desktop\heritagecove.com\db\dynamic.mdb;Password=;Jet OLEDB:Engine Type=5;Jet OLEDB:Global Bulk Transactions=1;Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:System database=;Jet OLEDB:SFP=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:New Database Password=;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Encrypt Database=False" Public Sub createreader(ByVal SQL As String) gErrorOccurred = False myconn = New OleDbConnection(strconn) mycommand = myconn.CreateCommand mycommand.CommandText = SQL Try myconn.Open() Catch ex As Exception MsgBox("The database is inaccessible. Please verify the Server is accessible and try again.", MsgBoxStyle.Critical, "Server Unavailable") gErrorOccurred = True Exit Sub End Try Try myreader = mycommand.ExecuteReader Catch ex As Exception MsgBox("The data source is unable to process the request. Please notify the system administrator." & vbCrLf & SQL, MsgBoxStyle.Critical, "SQL Error") gErrorOccurred = True Exit Sub End Try End Sub Public Sub closereader() myreader.Close() myconn.Close() End Sub Public Sub executecommand(ByVal sql As String) Dim cmd As New OleDbCommand(sql, New OleDbConnection(strconn)) Try cmd.Connection.Open() cmd.ExecuteNonQuery() cmd.Connection.Close() Catch ex As Exception 'MsgBox(ex.Message, MsgBoxStyle.OKOnly) End Try Here is the code im writing to try to get info from the database. Dim sql As String Dim myds As New DataSet sql = "SELECT FileName from Gallery Where ID IS NOT NULL" createreader(sql) Do While myreader.Read Label1.Text = myreader.G
-
Ok im new to asp.net and im having trouble trying to populate a label with info from my database. Here is the code i have Imports System.Data.OleDb Module Module1 Public myconn As OleDbConnection Public mycommand As OleDbCommand Public myreader As OleDbDataReader Public gErrorOccurred As Boolean Public p Public strconn As String = "Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Database Password=;Data Source=D:\Documents and Settings\Tommy's\Desktop\heritagecove.com\db\dynamic.mdb;Password=;Jet OLEDB:Engine Type=5;Jet OLEDB:Global Bulk Transactions=1;Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:System database=;Jet OLEDB:SFP=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:New Database Password=;Jet OLEDB:Create System Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Encrypt Database=False" Public Sub createreader(ByVal SQL As String) gErrorOccurred = False myconn = New OleDbConnection(strconn) mycommand = myconn.CreateCommand mycommand.CommandText = SQL Try myconn.Open() Catch ex As Exception MsgBox("The database is inaccessible. Please verify the Server is accessible and try again.", MsgBoxStyle.Critical, "Server Unavailable") gErrorOccurred = True Exit Sub End Try Try myreader = mycommand.ExecuteReader Catch ex As Exception MsgBox("The data source is unable to process the request. Please notify the system administrator." & vbCrLf & SQL, MsgBoxStyle.Critical, "SQL Error") gErrorOccurred = True Exit Sub End Try End Sub Public Sub closereader() myreader.Close() myconn.Close() End Sub Public Sub executecommand(ByVal sql As String) Dim cmd As New OleDbCommand(sql, New OleDbConnection(strconn)) Try cmd.Connection.Open() cmd.ExecuteNonQuery() cmd.Connection.Close() Catch ex As Exception 'MsgBox(ex.Message, MsgBoxStyle.OKOnly) End Try Here is the code im writing to try to get info from the database. Dim sql As String Dim myds As New DataSet sql = "SELECT FileName from Gallery Where ID IS NOT NULL" createreader(sql) Do While myreader.Read Label1.Text = myreader.G
Hi there. For starters, if you are executing this code in the context of an ASP.NET application, you can't use the
MsgBox()
function. That would be appropriate in a Windows Forms application, but not for ASP.NET. You would more likely want to let ASP.NET render the exception details to the browser, say, by setting aLabel.Text
value to theException.ToString()
, or execute aResponse.Write(ex.ToString())
, or aTrace.Write(ex.ToString())
, or something like that. There are a bunch of reasons why your database code may not be working - it's common when working with an Access database for example to run across permissions issues (the ASP.NET user not only needs access to the .mdb file, but must also have write access to the .mdb's containing folder). But until you know the specific details of the exception (and possibly details of the exception'sInnerException
property), it will be tough to tell. -
Hi there. For starters, if you are executing this code in the context of an ASP.NET application, you can't use the
MsgBox()
function. That would be appropriate in a Windows Forms application, but not for ASP.NET. You would more likely want to let ASP.NET render the exception details to the browser, say, by setting aLabel.Text
value to theException.ToString()
, or execute aResponse.Write(ex.ToString())
, or aTrace.Write(ex.ToString())
, or something like that. There are a bunch of reasons why your database code may not be working - it's common when working with an Access database for example to run across permissions issues (the ASP.NET user not only needs access to the .mdb file, but must also have write access to the .mdb's containing folder). But until you know the specific details of the exception (and possibly details of the exception'sInnerException
property), it will be tough to tell.It seems to be getting errored out at the myreader.read and or the myreader.getvalue(0) any ideas anyone?
-
It seems to be getting errored out at the myreader.read and or the myreader.getvalue(0) any ideas anyone?
But what are the details of the exception? It's good to know that the error is happening on a particular line, but what is the specfic exception you're getting?