使用OLEDB我的代碼波紋管,我得到這個錯誤:內
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();
}
我得到這個錯誤「的行/列不存在任何數據。」我添加了這個:'mycomm.Parameters.AddWithValue(「tblCodons.codonsCodon1」,letter);' – Noam650 2012-04-25 15:13:07
我試過了,我得到這個錯誤'行/列沒有數據存在。 ' – Noam650 2012-04-25 15:16:47
@ Noam650:我已經爲正確的語法添加了一個示例。 – Heinzi 2012-04-25 15:44:59