本帖最后由 wang346351 于 2013-4-18 16:05 编辑
- string sql = "select StudentID,Name,Sex,Age,School,ByTime from Student";
- if (!string.IsNullOrEmpty(this.txtName.Text))
- {
- sql += "where Name like '%" + this.txtName.Text + "%'";
- }
- SqlConnection conn = new SqlConnection("Data Source=WANG-PC;Initial Catalog=WANG;User ID=sa;Password=123");
- conn.Open();
- SqlDataAdapter da=new SqlDataAdapter();
- da.SelectCommand=new SqlCommand();
- da.SelectCommand.Connection=conn;
- da.SelectCommand.CommandText=sql;
- da.SelectCommand.CommandType=CommandType.Text;
- DataSet ds = new DataSet();
- da.Fill(ds);
- conn.Close();
- conn.Dispose();
复制代码
sql语句好像没错啊 怎么老是报这个错误,,,, |