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();
当我在没有 where 条件的情况下尝试但它不起作用时,请帮助我
最佳答案
我认为这是
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# - 错误 :Index (zero based) must be greater than or equal to zero and less than the size of the argument list,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18639356/