日期:2014-05-17  浏览次数:20852 次

sql语句总是报错: 至少一个参数没有被指定值 ???求大神指点
private void selectNumbers(int index,string ways)
  {
  string types="";
  switch (index)
  {
  case 0: types="";break ;
  case 1: types = "where num_name=" + ways; break;
  case 2: types = "where num_telephone="+ways; break;
  case 3: types = "where depart_name=" +ways; break;
  case 4: types = "where num_grad=" +ways; break;
  case 5: types = "where num_colloge=" +ways; break;

  }
  string dbsting = Application.StartupPath + "\\Access\\CMS.mdb";
  string sql= " select num_name,num_sex,num_telephone,num_colloge,num_professional,num_grad,depart_name ,num_position,num_introduction from numbertable "+types;
  MessageBox.Show(sql);
  OleDbConnection conn = db_interface.db_connection(dbsting);
  OleDbCommand comm = new OleDbCommand(sql ,conn );

在 OleDbDataReader odr = comm.ExecuteReader()语句总是报错!不知道为什么,我单独的进行查询是可以通过,但只要按照上面的代码就出错!


------解决方案--------------------
字符串要加单引号吧


case 1: types = "where num_name='" + ways + "'"; break;

SQL Server里肯定是这样,不知道access是不是一样。
------解决方案--------------------
探讨

字符串要加单引号吧


case 1: types = "where num_name='" + ways + "'"; break;

SQL Server里肯定是这样,不知道access是不是一样。