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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:04:13+00:00 2026-05-27T18:04:13+00:00

I am creating a datatable: public DataTable dt; public ReadFileIntoDataTable(string inputfile) { dt =

  • 0

I am creating a datatable:

    public DataTable dt;
    public ReadFileIntoDataTable(string inputfile)
    {
        dt = new DataTable();
        dt.Columns.Add("Specimen_ID",typeof(string));
        dt.Columns.Add("Client_Key",typeof(int));
        dt.Columns.Add("Outcome",typeof(string));
        dt.Columns.Add("Medications",typeof(string));
        dt.Columns.Add("Date_Collected",typeof(DateTime));
        dt.Columns.Add("Time_Collected",typeof(DateTime));
        dt.Columns.Add("Date_Entered",typeof(DateTime));
        dt.Columns.Add("Time_Entered",typeof(DateTime));
        dt.Columns.Add("Date_Completed",typeof(DateTime));
        dt.Columns.Add("Time_Completed",typeof(DateTime));
        dt.Columns.Add("Test_Date",typeof(DateTime));
        dt.Columns.Add("Test_Time",typeof(DateTime));
        dt.Columns.Add("Practice_Name",typeof(string));
        dt.Columns.Add("Practice_Code",typeof(string));
        dt.Columns.Add("Client_ID",typeof(string));
        dt.Columns.Add("Requesting_Physician",typeof(string));
        dt.Columns.Add("Other_Medications",typeof(string));
        dt.Columns.Add("Order_Comments",typeof(string));
        dt.Columns.Add("Reference_Number",typeof(string));
        dt.Columns.Add("Order_Count",typeof(int));
        dt.Columns.Add("_6_MAM_HEROIN_METABOLITE",typeof(decimal));
        dt.Columns.Add("_6_MAM_N_HEROIN_METABOLITE",typeof(decimal));
        dt.Columns.Add("_6_MAM_S_HEROIN_METABOLITE",typeof(decimal));
        dt.Columns.Add("_6_MAM_SN_HEROIN_METABOLITE",typeof(decimal));
        dt.Columns.Add("_6_MAM_SP_HEROIN_METABOLITE",typeof(decimal));
...
..
..

            string Specimen_ID;
            string Client_Key;
            string Outcome;
            string Medications;
            string Date_Collected;
            string Time_Collected;
            string Date_Entered;
            string Time_Entered;
            string Date_Completed;
            string Time_Completed;
            string Test_Date;
            string Test_Time;
            string Practice_Name;
            string Practice_Code;
            string Client_ID;
            string Requesting_Physician;
            string Other_Medications;
            string Order_Comments;
            string Reference_Number;
            string Order_Count;
            string _6_MAM_HEROIN_METABOLITE;
            string _6_MAM_N_HEROIN_METABOLITE;
            string _6_MAM_S_HEROIN_METABOLITE;
            string _6_MAM_SN_HEROIN_METABOLITE;
            string _6_MAM_SP_HEROIN_METABOLITE;
            string _6ACE_C_6_MAM__Heroin_metabolite;

.....
........
.....
            using (GenericParser parser = new GenericParser())
            {
                parser.SetDataSource(inputfile);

                char[] delimiters = new char[] { ',' };
                parser.ColumnDelimiter = delimiters[0];
                parser.FirstRowHasHeader = true;
                //parser.SkipDataRows = 10;
                parser.MaxBufferSize = 4096;
                parser.MaxRows = 500;
                parser.TextQualifier = '\"';


                while (parser.Read())
                {
                    Specimen_ID = parser["Specimen ID"];
                    Client_Key = parser["Client Key"];
                    Outcome = parser["Outcome"];
                    Medications = parser["Medications"];
                    Date_Collected = parser["Date Collected"];
                    Time_Collected = parser["Time Collected"];
                    Date_Entered = parser["Date Entered"];
                    Time_Entered = parser["Time Entered"];
                    Date_Completed = parser["Date Completed"];
                    Time_Completed = parser["Time Completed"];
                    Test_Date = parser["Test Date"];
                    Test_Time = parser["Test Time"];
                    Practice_Name = parser["Practice Name"];
                    Practice_Code = parser["Practice Code"];
                    Client_ID = parser["Client ID"];
                    Requesting_Physician = parser["Requesting Physician"];
                    Other_Medications = parser["Other Medications"];
                    Order_Comments = parser["Order Comments"];
                    Reference_Number = parser["Reference Number"];
                    Order_Count = parser["Order Count"];
                    _6_MAM_HEROIN_METABOLITE = parser["6-MAM-HEROIN METABOLITE"];

                    _6_MAM_N_HEROIN_METABOLITE = parser["6-MAM_N-HEROIN METABOLITE"];
                    _6_MAM_S_HEROIN_METABOLITE = parser["6-MAM_S-HEROIN METABOLITE"];
                    _6_MAM_SN_HEROIN_METABOLITE = parser["6-MAM_SN-HEROIN METABOLITE"];
                    _6_MAM_SP_HEROIN_METABOLITE = parser["6-MAM_SP-HEROIN METABOLITE"];
                    _6ACE_C_6_MAM__Heroin_metabolite = parser["6ACE_C-6-MAM (Heroin metabolite)"];

.....
......
.......

                    DataRow newRow = dt.NewRow();
                    newRow["Specimen_ID"] = Specimen_ID;
                    newRow["Client_Key"] = Client_Key;
                    newRow["Outcome"] = Outcome;
                    newRow["Medications"] = Medications;
                    newRow["Date_Collected"] = Date_Collected;
                    newRow["Time_Collected"] = Time_Collected;
                    newRow["Date_Entered"] = Date_Entered;
                    newRow["Time_Entered"] = Time_Entered;
                    newRow["Date_Completed"] = Date_Completed;
                    newRow["Time_Completed"] = Time_Completed;
                    newRow["Test_Date"] = Test_Date;
                    newRow["Test_Time"] = Test_Time;
                    newRow["Practice_Name"] = Practice_Name;
                    newRow["Practice_Code"] = Practice_Code;
                    newRow["Client_ID"] = Client_ID;
                    newRow["Requesting_Physician"] = Requesting_Physician;
                    newRow["Other_Medications"] = Other_Medications;
                    newRow["Order_Comments"] = Order_Comments;
                    newRow["Reference_Number"] = Reference_Number;
                    newRow["Order_Count"] = Order_Count;
                    newRow["_6_MAM_HEROIN_METABOLITE"] = ????
                    newRow["_6_MAM_N_HEROIN_METABOLITE"] = _6_MAM_N_HEROIN_METABOLITE;
                    newRow["_6_MAM_S_HEROIN_METABOLITE"] = _6_MAM_S_HEROIN_METABOLITE;
                    newRow["_6_MAM_SN_HEROIN_METABOLITE"] = _6_MAM_SN_HEROIN_METABOLITE;
                    newRow["_6_MAM_SP_HEROIN_METABOLITE"] = _6_MAM_SP_HEROIN_METABOLITE;


.........
........
......

As you can see I am doing the following:

  1. creating datatable
  2. parsing a file using genericparser
  3. inserting data into datatable from the file

My problem is when the file does not have a value for a field of type DECIMAL. I get the following error:

System.ArgumentException: Input string was not in a correct format.Couldn't store <> in _6_MAM_HEROIN_METABOLITE Column.  Expected type is Decimal. ---> System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt)
   at System.String.System.IConvertible.ToDecimal(IFormatProvider provider)
   at System.Data.Common.DecimalStorage.Set(Int32 record, Object value)
   at System.Data.DataColumn.set_Item(Int32 record, Object value)
   --- End of inner exception stack trace ---
   at System.Data.DataColumn.set_Item(Int32 record, Object value)
   at System.Data.DataRow.set_Item(DataColumn column, Object value)
   at CreateTableScript.ReadFileIntoDataTable..ctor(String inputfile) in C:\Users\agordon\Documents\Visual Studio 2008\Projects\SubversionRepository\Internal Application\SalesDWH\CreateTableScript\CreateTableScript\ReadFileIntoDataTable.cs:line 930
   at CreateTableScript.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\agordon\Documents\Visual Studio 2008\Projects\SubversionRepository\Internal Application\SalesDWH\CreateTableScript\CreateTableScript\Form1.cs:line 33
  • 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-27T18:04:14+00:00Added an answer on May 27, 2026 at 6:04 pm

    then do not set the value at all and the default value assigned in the data table will be used. you can change the default value to 0, a non-zero or DbNull.Value

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In runtime I'm creating a DataTable and using nested for-loops to populate the table.
How can I load a CSV file into a System.Data.DataTable , creating the datatable
c#/oop noob here. I am creating a datatable from the schema of a sql
In C#, I'm creating an XML file from a DataTable using dataTable.WriteXml(filePath), and get
My code for creating the data table looks like this: myDataTable = new YAHOO.widget.ScrollingDataTable(
I have a DataTable that I'm creating an XML file from using .WriteXML(..), although
I am new in creating application in Visual Studio 2010. I recently created an
I've got an odd issue. I'm creating a DataTable type my application then converting
I'm creating a dynamic GridView from a DataTable that is returned from a stored
No database involved here, I am creating my own datatable in code, and binding

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.