0

i'm running C# on a windows application and found a problem.
I'm unable to Check if a row from my data grid contains a null value, because im populating the rows for the datagrid from a CSV file and after that i need to populate that csv file into my database.

if (da.Tables["stocks"].Rows[i].ItemArray.GetValue(0) == "null")
    {
     //to insert on another table or create a file to dump the info another csx
    }
else
{
  cmd.CommandText = "Insert  into Test values('" +da.Tables["data"].Rows[i].ItemArray.GetValue(0) + "','" + da.Tables["data"].Rows[i].ItemArray.GetValue(1) + "','" + da.Tables["data"].Rows[i].ItemArray.GetValue(2) + "')";
cmd.ExecuteNonQuery();
                            
                           
 }
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Hyperion
0

This is not how you test for null values

if (da.Tables["stocks"].Rows[i].ItemArray.GetValue(0) == "null")

That tested for a string "null"

Rather try and use:

if (da.Tables["stocks"].Rows[i].ItemArray.GetValue(0) == null)

Also, please use more descriptive headings for you posts, I don't expect to "C#" titled post in a C# forum :D

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.