the result for value1 is giving error. col2 's datatype is int. col1 's datatype is string. even though i bring the string value or int value in if condition it accepts int value only.
string str = "SELECT col1,"
+ "if(col2=0,col1,col2) col2,"
+ "col3"
+ "FROM table1"
+ "ORDER BY col1 ASC";
connection.Open();
cmd = new MySqlCommand(strdept_name, connection);
adapter = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
connection.Close();
cmd.Parameters.Clear();
string value1 = dt.Rows[i].Field<string>("col2").ToString();
Please help me understand what is wrong here?
You can change col2 to string with concat('',col2) or convert col1 to int, choose one.
string str = "SELECT col1,"
+ "if(col2=0,col1,concat('',col2)) col2,"
+ "col3"
+ "FROM table1"
+ "ORDER BY col1 ASC";
connection.Open();
cmd = new MySqlCommand(strdept_name, connection);
adapter = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
connection.Close();
cmd.Parameters.Clear();
string value1 = dt.Rows[i]["col2"].ToString();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.