public partial class User_Default2 : System.Web.UI.Page
{
    public string sql, sqls, sqlm, AdInfo_ID, url, aids, info;
    public int uaid;
    public double sumprice;
    protected System.Data.SqlClient.SqlCommand cmd;
    protected System.Data.SqlClient.SqlConnection conn;
    public DataSet ds;
    Utils uitls = new Utils();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DateTime date = DateTime.Now;
            String YMD1 = date.ToShortDateString().ToString();
            String YMD2 = date.AddDays(1.1).ToShortDateString().ToString();
            CalendarInput1.Text = YMD1.ToString();
            CalendarInput2.Text = YMD2.ToString();
        }
        if (Session["user"] == null)
            Response.Redirect("Login_user.aspx");
        else
            power_sql();
    }    private void power_sql()
    {
        conn = uitls.conn();
        CheckAdInfoSort();
        FirstBindData();
    }    public void CheckAdInfoSort()   
    {
        string rq1, rq2, caller,callnum;
        rq1 = CalendarInput1.Text.Trim();
        rq2 = CalendarInput2.Text.Trim();
        caller = Session["user"].ToString();
        callnum = uitls.FiledValue("select top 1 usernum from userinfo_cb where bak_phoneno='" + caller + "'");
        if (rq1 == "" && rq2 == "")
        {
            sql = "select count(*) from SysFeeDate_CB where usernum='"+callnum+"' or callernum='"+caller+"' and fee>0";
            sqls = "select starttime,usernum,calleenum,holdmin,fee*0.01 as fee,calltype from SysFeeDate_CB where usernum='" + callnum + "' or callernum='" + caller + "' and fee>0 order by id desc";
        }
        else
        {
            //sql = "select count(*) from SysFeeDate_CB where (usernum='" + callnum + "' or callernum='" + caller + "') and starttime>'" + rq1 + "' and starttime<'" + rq2 + " 23:59:59' and fee>0";
            //sqls = "select starttime,usernum,calleenum,holdmin,fee*0.01 as fee from SysFeeDate_CB where (usernum='" + callnum + "' or callernum='" + caller + "') and starttime>'" + rq1 + "' and starttime<'" + rq2 + " 23:59:59' and fee>0";
            sql = "select count(*) from SysFeeDate_CB where starttime>'" + rq1 + "' and starttime<'" + rq2 + " 23:59:59' and fee>0 and ((calltype in (1,2) and callernum='"+caller+"') or (calleenum='"+caller+"' and calltype=0))";
            sqls = "select starttime,usernum,calleenum,holdmin,fee*0.01 as fee,calltype from SysFeeDate_CB where starttime>'" + rq1 + "' and starttime<'" + rq2 + " 23:59:59' and fee>0 and ((calltype in (1,2) and callernum='"+caller+"') or (calleenum='"+caller+"' and calltype=0))";
        }
    }
    public void FirstBindData()
    {
        try
        {
            cmd = new SqlCommand(sql, conn);
            conn.Open();
            pager.RecordCount = (int)cmd.ExecuteScalar();
            if (pager.RecordCount == 0)
                Label1.Text = "所选时间内无记录";
            else
            {
                conn.Close();
                Label1.Text = "";
            }
        }
        catch (Exception ex)
        {
            //Response.Write(sqls);
            Label1.Text = ex.Message;
        }
        BindData();
    }    public void BindData()
    {
        try
        {
            cmd = new SqlCommand(sqls, conn);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            ds = new DataSet();
            adapter.Fill(ds, pager.PageSize * (pager.CurrentPageIndex - 1), pager.PageSize, "SLC_call");
            adapter.Fill(ds, "result");
            
           
            for (int i = 0; i < ds.Tables["SLC_call"].Rows.Count; i++)     //循环表记录,进行更改字段内容
            {
                string memo;
                memo = ds.Tables["SLC_call"].Rows[i]["calltype"].ToString();
                if (memo =="2")
                    ds.Tables["SLC_call"].Rows[i]["calltype"] = "是";
                else
                    ds.Tables["SLC_call"].Rows[i]["calltype"] = "否";
        }
            DataGrid1.DataSource = ds.Tables["SlC_call"];
            DataGrid1.DataBind();
        }
        catch (Exception ex)
        {
            //Response.Write("<script>alert('错误的操作,请查看您的选择日期或与网站管理人员联系.')</script>");
            Response.Write(ex.Message);
        }
        AddCustomText();
    }    }
问题如下:  for (int i = 0; i < ds.Tables["SLC_call"].Rows.Count; i++)     //循环表记录,进行更改字段内容
            {
                string memo;
                memo = ds.Tables["SLC_call"].Rows[i]["calltype"].ToString();
                if (memo =="2")
                    ds.Tables["SLC_call"].Rows[i]["calltype"] = "是";
                else
                    ds.Tables["SLC_call"].Rows[i]["calltype"] = "否";
这里的'是'和'否'查询出来后,出错,显示:'Value was either too large or too small for an unsigned byte.Couldn't store <是> in calltype Column. Expected type is Byte'
我数据库中的calltype类型是tinyint 长度是1.现在是我想查询出来后,更改字段显示内容,可是用汉字就是不行,把这里的是和否换成汉字就可以的?
请问高手们如何转换?如何查询显示出来呢?

解决方案 »

  1.   

    改calltype类型,tinyint类型是:短整型,而你改成的“是”,“否”是字符串类型!
      

  2.   

    ds.Tables["SLC_call"].Rows[i]["calltype"]   这些值是object类型的`直接给“是”"否"是肯定 不对的`~你可这样再定义一个变量`string aa=ds.Tables["SLC_call"].Rows[i]["calltype"].ToString(); 再对aa转换 成int类型的数组`那两个汉字也是一个道理`这是是有点啰嗦 不过可以解决问题 
      

  3.   

    在SQL里加一显示列,然后再在代码里循环赋值;如果只是简单的查询显示,最好是直接在SQL里格式化
      

  4.   

    你在sql里只接用一case when转成是或否不就结了啊。
      

  5.   

    第二次问这个问题啦  直接判断ds的值 然后给gridview赋相应的值就好了啊
      

  6.   

    sql这样写就行了。
    sqls = "select starttime,usernum,calleenum,holdmin,fee*0.01 as fee,
    case
    when calltype =2 then '是'
    else '否'
    end as calltype
    from SysFeeDate_CB where usernum='" + callnum + "' or callernum='" + caller + "' and fee>0 order by id desc";
          
    然行以下垃圾代码删除 
    for (int i = 0; i < ds.Tables["SLC_call"].Rows.Count; i++)     //循环表记录,进行更改字段内容
                {
                    string memo;
                    memo = ds.Tables["SLC_call"].Rows[i]["calltype"].ToString();
                    if (memo =="2")
                        ds.Tables["SLC_call"].Rows[i]["calltype"] = "是";
                    else
                        ds.Tables["SLC_call"].Rows[i]["calltype"] = "否";
            }
      

  7.   

    我用过case了,可是不行.2楼的我没有看明白?怎么写呢?谢谢!我菜
      

  8.   

    根据数据库中的字段数值判断,在GridView里显示汉字。
    if(value=1)
    {
      ((TextBox)this.gv.FindControl("txtbox")).Text="是";
    }
    手写的,没调试。
      

  9.   

    你在sql里只接用一case when转成是或否不就结了啊。
    邦定的時候不去更改數據庫裏面的值!!!
      

  10.   

    看到大段代码就头晕。直接从问题如下开始不就得了。用case应该可以解决的,楼主把你怎么用的case那一段语句贴出来和DataGrid是怎么绑定的那一段贴出来就行了,千万别再贴那~~~么大一段代码了。
      

  11.   

    第一个办法:写sql语句的时候,用case when
    第二个办法:绑定数据的时候,表格里的显示时处理
      

  12.   

    这样行的/.不用SQL语句怎么实现呢?