c# – 错误:索引(从零开始)必须大于或等于零且小于参数列表的大小

c# – 错误:索引(从零开始)必须大于或等于零且小于参数列表的大小,第1张

概述SqlConnection cn = new SqlConnection("server=localhost;initial catalog=newmits;trusted_connection=true");cn.Open();string a = string.Format("select * from upnotice where show like '{0}' ,%t");SqlDa
sqlConnection cn = new sqlConnection("server=localhost;initial catalog=newmits;trusted_connection=true");cn.open();string a = string.Format("select * from upnotice where show like '{0}',%t");sqlDataAdapter adp1 = new sqlDataAdapter(a,cn);DataSet ds1 = new DataSet(); adp1.Fill(ds1);GrIDVIEw1.DataSource = ds1;GrIDVIEw1.DataBind();

当我在没有条件的情况下尝试它可以工作但是在它无法工作的地方请帮助我

解决方法 我假设这个

string a = string.Format("select * from upnotice where show like '{0}',%t");

应该

string a = string.Format("select * from upnotice where show like '{0}'","%t");

每个格式项(例如{0}或{1})都需要具有相应的参数.

但是,您不应该使用string.Format而是使用sql-parameters到prevent sql-injection.

总结

以上是内存溢出为你收集整理的c# – 错误:索引(从零开始)必须大于或等于零且小于参数列表的大小全部内容,希望文章能够帮你解决c# – 错误:索引(从零开始)必须大于或等于零且小于参数列表的大小所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1218454.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存