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 7913277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:48:15+00:00 2026-06-03T13:48:15+00:00

This works as long as every ‘item’ is numeric OR every item is alpha

  • 0

This works as long as every ‘item’ is numeric OR every item is alpha numeric. When i have ‘items’ that are numeric AND alpha numeric it does not fill in the values correctly.

Here is the code:

public void updateInventory()
{
    try
    {
        if (File.Exists(inventoryUpdateDirectory + "inventoryUpdate.csv"))
        {
            csvReader csv = new csvReader();
            DataTable inventory = csv.read(inventoryUpdateDirectory + "inventoryUpdate.csv");
            //int test = inventory.Rows.Count;
            string sql = "";

            foreach (DataRow inventoryItem in inventory.Rows)
            {
                try
                {
                    sql = " Update Inventory set OnHand = " + inventoryItem[1] + " WHERE Sku = '" + inventoryItem[0].ToString().Trim() + "'";
                    //executeSQL(sql);
                }
                catch { }
            }

            File.Delete(inventoryUpdateDirectory + "inventoryUpdate.csv");
        }
        else
        {
            writeToFile("fileDoesntExist", inventoryUpdateDirectory + "error.txt");
        }
    }
    catch { }
}

Here is the file it reads:

ALB001,0
ALB002,66
10001,0
10016,348

This will work:

ALB001,0
ALB002,66

This will work:

10001,0
10016,348

This will not work:

ALB001,0
ALB002,66
10001,0
10016,348

It fills out the inventoryItem array as an empty {}

+       inventoryItem[0]    {}  object {System.DBNull}

Which should have the value of ALB001

The first ‘column’ in the CSV should always be treated as a string as it can contain numbers of letters, the second ‘column’ will always be numbers.

Anyone able to help me figure this out?

I think I just need to edit the sql query to cast them as a string but I’m not sure.

CSV READER EDIT:

namespace CSV
{
    public class csvReader
    {
        public DataTable read(string strFileName)
        {
            OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source = " + System.IO.Path.GetDirectoryName(strFileName) + "; Extended Properties = \"Text;HDR=NO;FMT=Delimited\"");
            conn.Open();
            string strQuery = "SELECT * FROM [" + System.IO.Path.GetFileName(strFileName) + "]";
            OleDbDataAdapter adapter = new OleDbDataAdapter(strQuery, conn);
            DataSet ds = new DataSet("CSV File");
            adapter.Fill(ds);
            return ds.Tables[0];
        }

        public DataTable read(string strFileName, bool firstRowHeaders)
        {
            string hdr = "NO";
            if (firstRowHeaders) { hdr = "YES"; }

            OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source = " + System.IO.Path.GetDirectoryName(strFileName) + "; Extended Properties = \"Text;HDR=" + hdr + ";FMT=Delimited\"");
            conn.Open();
            string strQuery = "SELECT * FROM [" + System.IO.Path.GetFileName(strFileName) + "]";
            OleDbDataAdapter adapter = new OleDbDataAdapter(strQuery, conn);
            DataSet ds = new DataSet("CSV File");
            adapter.Fill(ds);
            return ds.Tables[0];
        }
    }
}
  • 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-06-03T13:48:16+00:00Added an answer on June 3, 2026 at 1:48 pm

    The problem is obviously in the CsvReader class. Since you didn’t attached its source code it is hard to know why it is not filling that datatable with the content and the best I can do is guess.

    I will try to help you by suggesting you to use this csv reader from codeproject:
    http://www.codeproject.com/Articles/86973/C-CSV-Reader-and-Writer

    you will not need to work with data tables as it enables you to iterate over the file rows using simple while loop. Your code will look like:

    using (CsvReader reader = new CsvReader(FilePath, Encoding.Default))
    {
       while (reader.ReadNextRecord())
       {
              sql = " Update Inventory set OnHand = " + reader.Fields[1] + " WHERE Sku = '" + reader.Fields[0] + "'";
       }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This works: var.replace(/[^0-9]+/g, ''); That simple snippet will replace anything that is not a
EDIT: It works but it takes amazingly long to complete. Is this normal, or
I have to work with strings which may contain Lat/Long data, like this: $query
I have a long, lazy sequence that I want to reduce and test lazily.
I found that this works sporadically, but usually doesn't work at all. $(window).unload(function() {
I'm calling setNeedsDisplayInRect from an NSTimer function every two seconds. This works perfectly, and
I've been thinking hard for a long time but couldn't work this out. Consider
This works fine: $.getJSON(http://localhost:59396/xxxWeb/ CarouselHandler.ashx?action=getproducts&ids= + ids, function(data) { carousel.size(allProductIDs.length); if (numberOfImagesLeftToShow < numberOfImagesToDisplay)
This works: Tweener.addTween( [ _fee, _fye, _fum ] , { alpna:1, time:10 }); But
This works perfectly if the priobann list is populated: banns << priobann?.pop() However, if

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.