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.现在是我想查询出来后,更改字段显示内容,可是用汉字就是不行,把这里的是和否换成汉字就可以的?
请问高手们如何转换?如何查询显示出来呢?
{
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.现在是我想查询出来后,更改字段显示内容,可是用汉字就是不行,把这里的是和否换成汉字就可以的?
请问高手们如何转换?如何查询显示出来呢?
解决方案 »
- NHibernate 引用下载
- 急救!!!this.listBox1.Items.Add问题!!
- 字符串小问题
- 请教c#项目中几个文件夹的作用?bin,obj,Properties,debug,release这几个文件夹.
- 截取字符串
- 多线程的,更新ui里的控件,最后实际更新的线程到底是UI线程还是别的线程?
- 关于用Java制作Webservice,用.net调用的问题
- 怎么样在VS.NET打开代码提示框?
- 如何在C#中将一个dbf文件转换为一个sql server的文件(编程实现)?
- 接收数据时read与receive的区别?帮忙!
- 为什么我的valign=middle不能垂直居中
- 高手们,问个问题哈,
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"] = "否";
}
if(value=1)
{
((TextBox)this.gv.FindControl("txtbox")).Text="是";
}
手写的,没调试。
邦定的時候不去更改數據庫裏面的值!!!
第二个办法:绑定数据的时候,表格里的显示时处理