value1的结果是错误。 col2的数据类型是int。 col1的数据类型是字符串。即使我在if条件中带来字符串值或int值,它只接受int值。
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();
请帮我理解这里有什么问题?
答案 0 :(得分:0)
您可以使用concat('',col2)将col2更改为字符串,或者将col1转换为int,选择一个。
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();