Johniek Comp
Johniek Comp

Reputation: 443

Change the value of the query

i have query i need change value, if value = "0000-00-00 00:00:00" then new value row = "no time", how?

dt.Load(cmd.ExecuteReader());
source.DataSource = dt;

so i use

source[2] = (source[2] == "0000-00-00 00:00:00") ? "no time" : source[2];  

but it`s wrong, i think need to use while?

Upvotes: 0

Views: 129

Answers (2)

Chibueze Opata
Chibueze Opata

Reputation: 10054

change to if statement:

if (source[2] == "0000-00-00 00:00:00") source[2] = "no time.";

Upvotes: 0

Adil
Adil

Reputation: 148120

It is betting to change the query of data source but if you do not have access over that for instance you get data from some third party web service, Assuming you do not want to change the why you get data from data source (Web service / Database) You can change in data table in C# code and assign to data source of your GUI control.

foreach (DataRow dr in dt.Rows)
{
     if (dr[2] == "0000-00-00 00:00:00")
         dr[2] = "No time"; // Use column name instead if possible dr["yourcolumnname"]
}

source.DataSource = dt;

Upvotes: 1

Related Questions