日期:2014-05-18  浏览次数:20673 次

请问这个from子句语法错误是怎么回事
代码如下
  string desid = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
  string strselect01 = "select A.checkid, A.checktime, A.bloodpressure, A.heartrate, A.temperature, A.weight, A.analysis, A.staffid, B.staffname from check as A, staff as B where A.staffid=B.staffid and desid=" + desid;
  OleDbConnection con = new OleDbConnection(strfilepath);
  OleDbCommand cmdselect01 = new OleDbCommand(strselect01, con);
  OleDbDataReader reader01;
  try
  {
  con.Open();
  reader01 = cmdselect01.ExecuteReader();
  reader01.Close();
  }
  catch (Exception ex)
  {
  MessageBox.Show(ex.ToString());
  }

运行的时候显示reader01 = cmdselect01.ExrcuteReader()这一行出错,说是FROM子句语法错误,但是我已经把复制到ACCESS里面运行过了,一切正常,求解~

------解决方案--------------------
string desid = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
输入一下看看,是否有值?是数字型的还是字符型的??

你的这个desid字段是A表的还是B表的??

加入你是B表的,并且desid是数字型的,还有check是Access中的关键字,需要用一对[]包起来,这样写试试看

string strselect01 = "select A.checkid, A.checktime, A.bloodpressure, A.heartrate, A.temperature, A.weight, A.analysis, A.staffid, B.staffname from [check] as A, staff as B where A.staffid=B.staffid and B.desid=" + int.Parse(desid);
------解决方案--------------------
SQL code

select 
A.checkid, A.checktime, A.bloodpressure, A.heartrate, 
A.temperature, A.weight, A.analysis, A.staffid, B.staffname 
from [check] A, staff B 
where A.staffid=B.staffid 
and desid=@desid;