注册 登录
编程论坛 ASP.NET技术论坛

将数据类型 nvarchar 转换为 numeric 时出错

guiqian145 发布于 2007-11-22 08:17, 5253 次点击
:victory:  strSql="select 职工姓名 from 职工基本表 where "+Session["word"]+"";
            string cns="Persist Security Info=False;User ID=sa;Initial Catalog=WLDB;Data Source=SUWENCHI";
            SqlConnection connsh=new SqlConnection(cns);
            connsh.Open();
            SqlDataAdapter adp=new SqlDataAdapter(strSql,connsh);
            DataSet ds =new DataSet();
            adp.Fill(ds,"职工基本表");
            this.DataGrid1.DataSource = ds;
            this.DataGrid1.DataBind() ;
其中Session["word"]是另一个页面TEXTBOX中的文本
运行时出现如下错误:
   将数据类型 nvarchar 转换为 numeric 时出错。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.SqlClient.SqlException: 将数据类型 nvarchar 转换为 numeric 时出错。
源错误:

行 42:             SqlDataAdapter adp=new SqlDataAdapter(strSql,connsh);
行 43:             DataSet ds =new DataSet();
行 44:             adp.Fill(ds,"职工基本表");
行 45:             this.DataGrid1.DataSource = ds;
行 46:             this.DataGrid1.DataBind() ;
大家帮帮忙!!!!
4 回复
#2
yelang72007-11-22 14:06
是你Session["word"]中出了错误.你仔细看下里面的内容.有字段的类型对不上的.
#3
bygg2007-11-22 16:59
Session["word"]  你的这个里面放的是什么啊??有没有对应到数据表中的某个字段?
#4
smoon2007-11-25 17:42
strSql="select 职工姓名 from 职工基本表 where "+Session["word"]+"";

把strSql这个打印出来看看是什么东西啊~
#5
jxnuwy042007-11-25 23:29
strSql="select 职工姓名 from 职工基本表 where "+Session["word"]+"";,这句话是什么意思,Session["word"]里存放的到底是什么?
大概存放的是条件,像"ID=某个值"这样的吧,不管存放的是什么,我想首先应该将它转换成string类型的吧,我想这个问题主要是在Session.
1