我有下面的代码,我收到了这个错误:
Troubleshooting Exceptions: System.Data.OleDb.OleDbException "syntax error"
我不知道我做错了什么。它假设从表中提取信息。我在整个项目上都使用了相同的方法,只是在这方面,它让我很麻烦......
class Codons
{
private bool start, end;
private string codon1, codon3, triplet1, triplet2, triplet3;
private string triplet4, triplet5, triplet6, fullName;
private OleDbConnection dataconnection;
public Codons(string letter)
{
this.start = false;
this.end = false;
this.dataconnection = new OleDbConnection();
this.dataconnection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Projects_2012\\Project_Noam\\Access\\myProject.accdb";
this.dataconnection.Open();
string sql = "SELECT tblCodons.codonsCodon3, " +
"tblCodons.codonsTriplet1, tblCodons.codonsTriplet2, tblCodons.codonsTriplet3, " +
"tblCodons.codonsTriplet4, tblCodons.codonsTriplet5, tblCodons.codonsTriplet6, " +
"tblCodons.codonsFullName, tblCodons.codonsStart, tblCodons.codonsEnd"
+ " FROM tblCodons"
+ " WHERE tblCodons.codonsCodon1="+letter;
OleDbCommand mycomm = new OleDbCommand(sql, dataconnection);
OleDbDataReader dataReader = mycomm.ExecuteReader();
dataReader.Read();
this.codon1 = letter;
this.codon3 = dataReader.GetString(0);
this.triplet1 = dataReader.GetString(1);
if (dataReader.IsDBNull(2))
this.triplet2 = " ";
else
this.triplet2 = dataReader.GetString(2);
if (dataReader.IsDBNull(3))
this.triplet3 = " ";
else
this.triplet3 = dataReader.GetString(3);
if (dataReader.IsDBNull(4))
this.triplet4 = " ";
else
this.triplet4 = dataReader.GetString(4);
if (dataReader.IsDBNull(5))
this.triplet5 = " ";
else
this.triplet5 = dataReader.GetString(5);
if (dataReader.IsDBNull(6))
this.triplet6 = " ";
else
this.triplet6 = dataReader.GetString(6);
this.fullName = dataReader.GetString(7);
this.start = dataReader.GetBoolean(8);
this.end = dataReader.GetBoolean(9);
dataReader.Close();
}