Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6246083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:37:27+00:00 2026-05-24T12:37:27+00:00

Im converting this simple program from vb to c# it updates, displays, create and

  • 0

Im converting this simple program from vb to c# it updates, displays, create and delete items from a little access database. Bellow is the PopulateListBox() function in VB it goes through every row in the data set and see if it is deleted, not deleted or has errors. I am getting 2 errors here both on the lines
lstAlbums.Items.Add(item);
and
lstAlbums.Items.Add(delitem);
now i realise that the strings are unassigned so i added
string item = “”;
string delitem = “”;

then when i start the program it fills every second item in th list box with a blank row.

How do i overcome this situation? thank you in advance anyone how can help me.

    private void PopulateListBox()
    {
        string item;
        string delitem;
        //clear the list box
        lstAlbums.Items.Clear();

        //access each row in the data set table

        foreach (DataRow row in myDataSet.Tables["albums"].Rows)
        {
            //list the nondeleted rows
            if (!((row.RowState & DataRowState.Deleted) == DataRowState.Deleted))
                item = row["albumCode"] + ", " + row["AlbumTitle"] + ", " +                                row["ArtistCode"];
                    //list rows with update errors
                    if (row.HasErrors)
                    item = "(**" + row.RowError + "**)";
                lstAlbums.Items.Add(item);

            //list deleted rows
            if ((row.RowState & DataRowState.Deleted) == DataRowState.Deleted)
                delitem = row["albumCode", DataRowVersion.Original] + ", " 
                    + row["AlbumTitle", DataRowVersion.Original] + ", " 
                    + row["ArtistCode", DataRowVersion.Original] + "***DELETED***";
            lstAlbums.Items.Add(delitem);
         }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:37:28+00:00Added an answer on May 24, 2026 at 12:37 pm

    You’re missing the opening and closing braces { and } in your if statement, so the statement immediately following the if statement executes if the condition matches, and the statement after that always executes.

    In VB.NET your if statement resembles this:

    If condition Then
        ' do something
        ' do something else
    End If
    

    To translate that to C# and properly execute the 2 lines of code you should use braces:

    if (condition)
    {
        // do something
        // do something else
    }
    

    Your current translation actually looks like this:

    if (condition)
        // do something (if condition is true)
    // do something else (not dependent on the condition)
    

    In other words the 2nd statement always executes. It’s a good practice to always enclose multiple statements within the braces to avoid such unintended circumstances.

    Change your code to this:

    if (!((row.RowState & DataRowState.Deleted) == DataRowState.Deleted))
    {
        item = row["albumCode"] + ", " + row["AlbumTitle"] + ", " +                                row["ArtistCode"];
        //list rows with update errors
        if (row.HasErrors)
        {
            item = "(**" + row.RowError + "**)";
        }
    
        lstAlbums.Items.Add(item);
    }
    
    //list deleted rows
    if ((row.RowState & DataRowState.Deleted) == DataRowState.Deleted)
    {
        delitem = row["albumCode", DataRowVersion.Original] + ", " 
            + row["AlbumTitle", DataRowVersion.Original] + ", " 
            + row["ArtistCode", DataRowVersion.Original] + "***DELETED***";
        lstAlbums.Items.Add(delitem);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am converting a linux script from http://www.perlmonks.org/index.pl?node_id=217166 specifically this: #!/usr/bin/perl -w use strict;
I've been looking for this for a while: I'm currently converting a medium-size program
I'm working on converting a rather large (but somewhat simple) app from Symfony to
I am converting a Fortran program to C#. This has to be done in
In this question superwiren asks about the pitfalls for converting a .net 2.0 solution
LearnWPF.com posted this article about converting bitmap images to XAML and using them in
Converting a couple stored procedures from MySQL to Microsoft SQL server. Everything is going
I am converting from existing CVS repository to SVN repository. CVS repository has few
I need to pre-produce a million or two PDF files from a simple template
Since I'm more comfortable using Eclipse, I thought I'd try converting my project from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.