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# – 错误:索引(从零开始)必须大于或等于零且小于参数列表的大小所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)