Click here to Skip to main content
15,914,163 members
Home / Discussions / C#
   

C#

 
GeneralRe: Responding to Web Browser generated MessageBox Pin
Lilith.C13-Mar-10 6:30
Lilith.C13-Mar-10 6:30 
GeneralRe: Responding to Web Browser generated MessageBox Pin
#realJSOP13-Mar-10 7:10
professional#realJSOP13-Mar-10 7:10 
QuestionDatabase not updating values - nullreference exception keeps getting thrown [modified] Pin
Eagle3212-Mar-10 13:13
Eagle3212-Mar-10 13:13 
Hi,

I am using SQL Server Compact 3.5 for my database.

I am trying to update the data in the database table, dataset and the gridview by looping through each of the datagridview row by doing the following:

for(int i = 0; i<AnimalsDataGridView.Rows.Count; i++)
{
   try
   {
    if (File.Exists(AnimalsDataGridView.Rows[i].Cells[4].Value.ToString()))
    {
      //get the filePath
      String currentPath = AnimalsDataGridView.Rows[i].Cells[4].Value.ToString();
      Image img = Image.FromFile(currentPath);
                        
      Image thumbnail = SetThumbnail(img, 200, 200);

      //get the title of the image and store in imageTitle variable
                        
       //save image to byte array
       byte[] imageInfo = ImageToByteArray(thumbnail);
                        
       //Primary key of the database. I have not enabled the autogeneration feature regarding this.
        Guid guid = getGuid(thumbnail);

       this.ZooTableAdapter.Update(guid, imageTitle, imageInfo, currentPath, guid);
       this.ZooTableAdapter.Fill(ZooDataSet.Animals);
    }
                    
  }
  catch (Exception e)
  {
    Console.WriteLine(e.Message.ToString());
  }
}


The error occurs on the the following line:
if (File.Exists(AnimalsDataGridView.Rows[i].Cells[4].Value.ToString()))


This is the error:
NullReference Exception was unhandled
Object reference not set to an instance of an object.


Is it because it is trying to update an empty row i.e the blank row?

The Update query looks like this:
UPDATE [Animals] SET [Id] = @p1, [Title] = @p2, [Thumbnail] = @p3, [FullPath] = @p4 WHERE (([Id] = @p5))



If somebody could assist me assist me with this problem, i would greatly appreciate the help.

Thanks in advance,
modified on Friday, March 12, 2010 7:42 PM

AnswerRe: Database not updating values - nullreference exception keeps getting thrown Pin
Dan Mos12-Mar-10 13:36
Dan Mos12-Mar-10 13:36 
GeneralRe: Database not updating values - nullreference exception keeps getting thrown Pin
Eagle3212-Mar-10 13:56
Eagle3212-Mar-10 13:56 
GeneralRe: Database not updating values - nullreference exception keeps getting thrown[modified] Pin
Dan Mos12-Mar-10 14:01
Dan Mos12-Mar-10 14:01 
GeneralRe: Database not updating values - nullreference exception keeps getting throw Pin
Eagle3213-Mar-10 2:23
Eagle3213-Mar-10 2:23 
GeneralRe: Database not updating values - nullreference exception keeps getting throw Pin
Dan Mos13-Mar-10 13:06
Dan Mos13-Mar-10 13:06 
QuestionSpeed difference between two functions with unknown reason Pin
SimpleData12-Mar-10 10:10
SimpleData12-Mar-10 10:10 
AnswerMessage Closed Pin
12-Mar-10 10:17
stancrm12-Mar-10 10:17 
GeneralRe: Speed difference between two functions with unknown reason Pin
SimpleData12-Mar-10 10:18
SimpleData12-Mar-10 10:18 
AnswerRe: Speed difference between two functions with unknown reason Pin
Luc Pattyn12-Mar-10 11:00
sitebuilderLuc Pattyn12-Mar-10 11:00 
GeneralRe: Speed difference between two functions with unknown reason Pin
SimpleData12-Mar-10 11:06
SimpleData12-Mar-10 11:06 
GeneralRe: Speed difference between two functions with unknown reason Pin
harold aptroot12-Mar-10 11:31
harold aptroot12-Mar-10 11:31 
GeneralRe: Speed difference between two functions with unknown reason Pin
Luc Pattyn12-Mar-10 11:41
sitebuilderLuc Pattyn12-Mar-10 11:41 
GeneralRe: Speed difference between two functions with unknown reason Pin
harold aptroot12-Mar-10 12:06
harold aptroot12-Mar-10 12:06 
GeneralRe: Speed difference between two functions with unknown reason Pin
Luc Pattyn12-Mar-10 12:29
sitebuilderLuc Pattyn12-Mar-10 12:29 
GeneralRe: Speed difference between two functions with unknown reason Pin
SimpleData12-Mar-10 22:35
SimpleData12-Mar-10 22:35 
GeneralRe: Speed difference between two functions with unknown reason Pin
SimpleData12-Mar-10 22:32
SimpleData12-Mar-10 22:32 
GeneralRe: Speed difference between two functions with unknown reason Pin
Pete O'Hanlon12-Mar-10 11:36
mvePete O'Hanlon12-Mar-10 11:36 
QuestionFloating child form linked to Treemap nodes Pin
boreland12-Mar-10 10:08
boreland12-Mar-10 10:08 
AnswerMessage Closed Pin
12-Mar-10 10:15
stancrm12-Mar-10 10:15 
GeneralRe: Floating child form linked to Treemap nodes [modified] Pin
boreland12-Mar-10 10:32
boreland12-Mar-10 10:32 
GeneralRe: Floating child form linked to Treemap nodes Pin
Dave Kreskowiak12-Mar-10 11:13
mveDave Kreskowiak12-Mar-10 11:13 
AnswerRe: Floating child form linked to Treemap nodes Pin
Luc Pattyn12-Mar-10 11:04
sitebuilderLuc Pattyn12-Mar-10 11:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.