string selectstr="select * from shebeiguanli where 地址="+address; 这一句有问题,你上面是模糊查询 string teststr="select count(*) from shebeiguanli where 地址 like'"+TextBox2.Text.Trim()+"'"; 有可能存在符合条件的记录,而你后面是指定条件条件,所以虽然前面的返回值小于0 但仍有可能后面没有满足条件的记录,所以你填充的时候会报错 解决方案,你把上面的那个查询满足条件记录数条件也换成= 即string teststr="select count(*) from shebeiguanli where 地址 ='"+TextBox2.Text.Trim()+"'";个为认为你这个查询写的有点儿复杂了,你可以直接去查询满足条件的记录adapter,然后判断其是不是一个空的记录集就行了,你这样前后有两次数据库的读取,不可取
输入145.146.0.60查询相关资料时 .0处发生错误.如果换145.146.17.139 则.17发生错误
-------------------------------------
提示一下,是不是数据库里面ip地址的字段长度定义的太小了,或者类型不匹配,或者楼主string teststr="select count(*) from shebeiguanli where 地址 like'"+TextBox2.Text.Trim()+"'";把count(*) 加个别名试试看。最好能把出错信息贴出来!
错误如下
如果输入145.146.0.60
第 1 行: '.0' 附近有语法错误。
异常详细信息: System.Data.SqlClient.SqlException: 第 1 行: '.0' 附近有语法错误。源错误:
行 115: SqlDataAdapter myadapter;
行 116: myadapter =new SqlDataAdapter(comm);
行 117: myadapter.Fill(ds);
行 118: TextBox1.Text=(string)ds.Tables[0].Rows[0]["MAC地址"];
行 119: TextBox1.Text=(string)ds.Tables[0].Rows[0]["地址"];
117行错误红色源文件: c:\inetpub\wwwroot\orientjfgl\webform1.aspx.cs 行: 117 堆栈跟踪:
[SqlException: 第 1 行: '.0' 附近有语法错误。]
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
System.Data.SqlClient.SqlCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
Orientjfgl.WebForm1.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\orientjfgl\webform1.aspx.cs:117
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()
这一句有问题,你上面是模糊查询
string teststr="select count(*) from shebeiguanli where 地址 like'"+TextBox2.Text.Trim()+"'";
有可能存在符合条件的记录,而你后面是指定条件条件,所以虽然前面的返回值小于0
但仍有可能后面没有满足条件的记录,所以你填充的时候会报错
解决方案,你把上面的那个查询满足条件记录数条件也换成=
即string teststr="select count(*) from shebeiguanli where 地址 ='"+TextBox2.Text.Trim()+"'";个为认为你这个查询写的有点儿复杂了,你可以直接去查询满足条件的记录adapter,然后判断其是不是一个空的记录集就行了,你这样前后有两次数据库的读取,不可取