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"; 

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.

2 Years
Discussion Span
Last Post by lithium112
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.