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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:24:42+00:00 2026-06-14T01:24:42+00:00

I have some data being shown in a DataGrid. The data comes from SQL,

  • 0

I have some data being shown in a DataGrid. The data comes from SQL, where a “money” type can be null. When i display this data, all is OK when i format the data in a double column format as currency. ie:

internal void FillGrid()
{

        bD = new DataTable();
        DataTable dt = EmployerQuery();  //queries the SQL DB


        bD.Columns.Add(new DataColumn("ID", typeof(int)));
        bD.Columns.Add(new DataColumn("EmployerName", typeof(string)));
        bD.Columns.Add(new DataColumn("FlatMinAmount", typeof(double)));
        bD.Columns.Add(new DataColumn("DistrictRate", typeof(double)));
        bD.Columns.Add(new DataColumn("VendorRate", typeof(double)));
        bD.Columns.Add(new DataColumn("Description", typeof(string)));
        bD.Columns.Add(new DataColumn("EmployeeCount", typeof(int)));

        foreach (DataRow sqlRow in dt.Rows)
        {
            var row = bD.NewRow();
            row["ID"] = sqlRow["ClientID"];
            row["EmployerName"] = sqlRow["OfficialName"];
            row["FlatMinAmount"] = sqlRow["FlatMinAmount"];
            row["DistrictRate"] = sqlRow["DistrictRate"];
            row["VendorRate"] = sqlRow["VendorRate"];
            row["Description"] = sqlRow["Description"];
            row["EmployeeCount"] = sqlRow["EmployeeCount"];

            bD.Rows.Add(row);

        }    

However, I then save the data as a .csv file. When i read that file back, the values for “FlatMinAmount” that were null are not allowed to be inserted into a column type double, so I cannot format the data columns as type double, since many are null.

<dg:DataGrid Name="newGrid" ItemsSource="{Binding ElementName=readGrid, Path=readGrid}" AutoGenerateColumns="False"
                 Margin="5" Height="175" Width="Auto" ColumnWidth="Auto">
        <dg:DataGrid.Columns>
            <dg:DataGridTextColumn Binding="{Binding ID}" Header="Employer ID" Width="Auto" IsReadOnly="True"/>
            <dg:DataGridTextColumn Binding="{Binding EmployerName}" Header="Employer Name" Width="Auto" IsReadOnly="True"/>
            <dg:DataGridTextColumn Binding="{Binding FlatMinAmount, StringFormat=C}" Header="FlatMinAmount" Width="Auto" IsReadOnly="True"/>
            <dg:DataGridTextColumn Binding="{Binding DistrictRate, StringFormat=C}" Header="District Rate" Width="Auto" IsReadOnly="True"/>
            <dg:DataGridTextColumn Binding="{Binding VendorRate, StringFormat=C}" Header="Vendor Rate" Width="Auto" IsReadOnly="True"/>
            <dg:DataGridTextColumn Binding="{Binding Description}" Header="Description" Width="Auto" IsReadOnly="True"/>
            <dg:DataGridTextColumn Binding="{Binding EmployeeCount}" Header="EmployeeCount" Width="*" IsReadOnly="True"/>
        </dg:DataGrid.Columns>
    </dg:DataGrid>


DataTable r = new DataTable();

        try
        {
            //string csv = string.Empty;

            //r.Columns.Add("ID", typeof(int));
            //r.Columns.Add("EmployerName", typeof(string));
            //r.Columns.Add("FlatMinAmount",typeof(double));
            //r.Columns.Add("DistrictRate", typeof(double));
            //r.Columns.Add("VendorRate", typeof(double));
            //r.Columns.Add("Description", typeof(string));
            //r.Columns.Add("EmployeeCount", typeof(int));

            r.Columns.Add("ID");
            r.Columns.Add("EmployerName");
            r.Columns.Add("FlatMinAmount");
            r.Columns.Add("DistrictRate");
            r.Columns.Add("VendorRate");
            r.Columns.Add("Description");
            r.Columns.Add("EmployeeCount");

            // Read sample data from CSV file
            using (CsvFileReader reader = new CsvFileReader(filename))
            {
                CsvRow row = new CsvRow();
                while (reader.ReadRow(row))
                {
                    //foreach (string s in row)
                    {
                        r.Rows.Add(row[0], row[1], row[2], row[3], row[4], row[5], row[6]);


                    }

                }
            }

(readGrid is then set to r in code-behind)

If they are string, then i cannot use the StringFormat=C in the binding to show $ etc. Also, it seems I cannot style a DataGridTextColumn. So, how can i display the values I read in from .csv as $xx.xx?

  • 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-14T01:24:44+00:00Added an answer on June 14, 2026 at 1:24 am

    If you know the number is null, can’t you just set the value of the column to DBNull?

    row["FlatMinAmount"] = DBNull.Value;
    

    Here’s a little console app I ran to show this working:

    class Program
        {
            static void Main(string[] args) {
                DataTable tbl = new DataTable();
                DataColumn col = new DataColumn("Blah", typeof(double));
                tbl.Columns.Add(col);
    
                DataRow row = tbl.NewRow();
                row["Blah"] = DBNull.Value;
    
                Console.WriteLine("Result: " + row["Blah"].ToString());
                Console.ReadKey();
    
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question regarding the some data which is being transfered from one
So I have some data in MySQL being shown on my PHP page inside
I have the following JSON data being returned, but for some reason, Javascript or
I have some data from log files and would like to group entries by
I have some data which (quite reasonably) uses null and false for different meanings.
I have some data and need to create a json file with this structure
Ok, i have some data that is being populated via a php query to
I have some data loaded as a np.ndarray and need to convert it to
I have some data files in the resources/ folder for my Rubymotion project. How
I have some data that is stored in a TIMESTAMP(6) WITH TIMEZONE column in

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.