繁体   English   中英

数据表:数据表结果中的 System.Byte[] 值

[英]Datatable: System.Byte[] value in datatable result

value1 的结果给出错误。 col2 的数据类型是 int。 col1 的数据类型是字符串。 即使我将字符串值或 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();

请帮我理解这里有什么问题?

您可以使用 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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM