Member Avatar for lithium112

Hello,

I am trying to change a column from "Null" to "1" in the SQL database. I have tried many things but everything has failed so far. I have tried foreach statements:

 foreach (DataRow dr in dt.Rows) // search whole table
{
   if (dr["ColumnName"] == null) 
   {
     dr["ColumnName"] = "1"; 
     break; 
   }
}

But this won't even enter into the foreach statement when I step line by line through the code.

I have also tried:

 if (dt.Rows[0].IsNull(0))
   {
                MessageBox.Show("Is Null!");
   }

(The messagebox is to test if it really works) This keeps giving me an error and will not show the messagebox. The error I get is that "There is no row at position 0." But I am looking right at the database and it has a record in there. So I am at a loss of what needs to be done, especially since I have a record in the database that has a null value in the column.

Any help would be much appreciated.

Member Avatar for lithium112

I created a SPROC for it. It works now!

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.