基础问题,点拨一下
String sqlConnection = "Data Source=(local);Initial Catalog=northwind;User Id=sa;Password=keshan;";
String strSQL = " select * from customers where customerid like @input ";
SqlConnection conn = new SqlConnection(sqlConnection);
conn.Open();
SqlCommand cmd = new SqlCommand(strSQL,conn);
SqlParameter sp = new SqlParameter("@input",SqlDbType.VarChar,20);
sp.Value = this.textBox1.Text;
cmd.Parameters.Add(sp);
问题1:String strSQL = " select * from customers where customerid like @input ";
的话,如果 textBox1 的值是空 那么运行的时候就 没有数据,我想,如果textBox1 的值是空那么显示全部数据?以前做项目没有使用参数,想问的是如果使用参数的话大家平常是怎么处理的?
问题2:比如说this.textBox1.Text 的值为 aaa
怎么控制sql语句为 select * from customers where customerid like 'aaa%'?