急:我用datagrid进行数据绑定,TextBox的内容为select数据的条件,当TextBox.text为数字时,运行正常,为字符时出错,代码如下

shevajmc 2004-08-19 09:59:01
sqlstring1="select * from ygdm where yg_ygxm = @yg_ygxm";

Cmd2.SelectCommand.Parameters.Add(new SqlParameter("@yg_ygxm",SqlDbType.VarChar,10)).Value = neirong.Text.Trim();

Server Error in '/yiliaofeibaoxiao' Application.
--------------------------------------------------------------------------------

Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:


Line 135: Conn.Open();
Line 136: DataSet ds2 = new DataSet();
Line 137: Cmd2.Fill(ds2, "ygdm");
Line 138: DataView dv2 = ds2.Tables["ygdm"].DefaultView;
Line 139: if (SortField!="")


Source File: c:\inetpub\wwwroot\yiliaofeibaoxiao\ygxxguanli.aspx.cs Line: 137

Stack Trace:


[FormatException: Input string was not in a correct format.]
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +723
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior) +45
System.Data.SqlClient.SqlCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +5
System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +304
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +77
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +36
yiliaofeibaoxiao.ygxxguanli.BindGridToSource(String SortField) in c:\inetpub\wwwroot\yiliaofeibaoxiao\ygxxguanli.aspx.cs:137
yiliaofeibaoxiao.ygxxguanli.BindGridToSource() in c:\inetpub\wwwroot\yiliaofeibaoxiao\ygxxguanli.aspx.cs:97
yiliaofeibaoxiao.ygxxguanli.chaxun_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\yiliaofeibaoxiao\ygxxguanli.aspx.cs:504
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277


...全文
147 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
vzxq 2004-08-19
  • 打赏
  • 举报
回复
"select * from ygdm where yg_ygxm = @yg_ygxm";
你在查询分析器中试试
ofei 2004-08-19
  • 打赏
  • 举报
回复
转一下类型

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧