I have a guest book application that uses ASP.Net and Microsoft Access. I have a table named EmailNotify that stores email addresses that will be sent email notifications every time someone signs the guest book. I am having some problems with the code. I think I'm missing something in the DataRow.
Here's the code that is significant:
Dim strConnect As String
Dim strSQL as String
Dim objConnect As New OleDbConnection()
Dim objCommand As New OleDbCommand()
Dim objDataAdapter As New OleDbDataAdapter()
Dim dtsGBook As New DataSet()
dim objDataRow as DataRow
Dim databaseName as String
Dim path as String
databaseName = "MyDatabase.mdb"
path = Server.MapPath(".")
path = Replace(path,"html","database")
'Create Connection object
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data " _
& ;nbs p; &a mp;n bsp; & "Source=" & path & "\" & databaseName
objConnect.ConnectionString = strConnect
objConnect.Open()
'Build sql string
strSQL = "Select * From EmailNotify"
'Set the Command Object properties
objCommand.Connection = objConnect
objCommand.CommandText = strSQL
'Fill the DataSet based on the SQL command
objDataAdapter.SelectCommand = objCommand
objDataAdapter.Fill(dtsGBook, "dttGBook")
'Create a DataRow object
'objDataRow = dtsGBook.Tables("dttGBook") - I tried doing this, but it would not work.
Dim GetEMail As String
&nbs p; GetEmail = objDataRow("Email").ToString()
I am getting the following error message:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 162:
Line 163: Dim GetEMail As String
Line 164: GetEmail = objDataRow("Email").ToString()
I tried adding 'Create a DataRow object
'objDataRow = dtsGBook.Tables("dttGBook") before line 162, but it would not work. I think that I am supposed to create a datarow object before line 164 will work. Can someone please help me with this?
Edited by Misty - 01 February 2005 at 1:46pm