Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Retrieving a Value from a DataRow Object
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Retrieving a Value from a DataRow Object

 Post Reply Post Reply
Author
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Topic: Retrieving a Value from a DataRow Object
    Posted: 01 February 2005 at 1:44pm
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
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 01 February 2005 at 4:20pm
Originally posted by Misty Misty wrote:

 
                 '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()
 
 
As for the first problem you encoutered
objDataRow=dtsGBook.Tables(...
that cannot work as you have a row on the left and a table on the right. Row <> Table.
You could do objDataRow=dsGBook.Tables(0).Rows(0)
to get the first row in the collection. But why so complicated? You have them all in your dataset so why not just go like
For i as Integer=0 to ds.Tables(0).Rows.Count-1
   Dim GetEmail as String
   GetEmail = ds.Tables(0).Rows(i).Item("Email").ToString
   'Do your think like sending email or whatever
Next i
Now I assume a loop is what you want to do but no matter what you should get the idea.
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 03 February 2005 at 1:25am
Michael,
 
Thank you! I did what you suggested. It worked very well.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.