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();
                            
                           
 }

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.