比较不同表中的值时出现语法错误
我在使用下面的代码时遇到“语法错误”。 当您输入该特定蛋白质的所有值时,它应该避免添加行(这是一个结合了生物学和编程的项目。 'serialPro' 是一个文本框,其中包含一个数字,但保存为字符串。 “Reset_Click”重置所有文本框。 代码:
if ((serialPro.Text == String.Empty) || (codon1.Text == String.Empty))
{
MessageBox.Show("You didn't fill all the fields","Attention"
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
Reset_Click(sender, e);
}
else
{
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Projects_2012\\Project_Noam\\Access\\myProject.accdb";
OleDbConnection myConnection = new OleDbConnection(connectionString);
myConnection.Open();
string mySQL = " SELECT COUNT(tblOrderAA.orderAASerialPro) AS orderAASerialPro1 FROM tblOrderAA" +
"WHERE tblOrderAA.orderAASerialPro=" + Convert.ToInt32(serialPro.Text) +
" SELECT (tblProInfo.proInfoSerialNum) FROM tblProInfo WHERE tblProInfo.proInfoSerialNum=" +
Convert.ToInt32(serialPro.Text);
OleDbCommand datacommand = new OleDbCommand(mySQL, myConnection);
OleDbDataReader dataReader = datacommand.ExecuteReader();
dataReader.Read();
if (dataReader.GetInt32(0) == dataReader.GetInt32(1))
{
MessageBox.Show("You have entered all the amino acids for this protein", "Attention",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
Reset_Click(sender, e);
}
TNX 寻求帮助!
I'm getting a "syntax error" while using the code below.
it suppoused to avoid adding row when you entered all the values of this specific protein(it is a project combined Biology and Programming.
'serialPro' is a textbox which contains a number,but saved as string.
'Reset_Click' resetes all textboxes.
THE CODE:
if ((serialPro.Text == String.Empty) || (codon1.Text == String.Empty))
{
MessageBox.Show("You didn't fill all the fields","Attention"
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
Reset_Click(sender, e);
}
else
{
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Projects_2012\\Project_Noam\\Access\\myProject.accdb";
OleDbConnection myConnection = new OleDbConnection(connectionString);
myConnection.Open();
string mySQL = " SELECT COUNT(tblOrderAA.orderAASerialPro) AS orderAASerialPro1 FROM tblOrderAA" +
"WHERE tblOrderAA.orderAASerialPro=" + Convert.ToInt32(serialPro.Text) +
" SELECT (tblProInfo.proInfoSerialNum) FROM tblProInfo WHERE tblProInfo.proInfoSerialNum=" +
Convert.ToInt32(serialPro.Text);
OleDbCommand datacommand = new OleDbCommand(mySQL, myConnection);
OleDbDataReader dataReader = datacommand.ExecuteReader();
dataReader.Read();
if (dataReader.GetInt32(0) == dataReader.GetInt32(1))
{
MessageBox.Show("You have entered all the amino acids for this protein", "Attention",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
Reset_Click(sender, e);
}
TNX for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定 MySQL 查询中的两个 select 语句是否有效,或者为什么您只将一个字符串转换为数字,以便可以将其添加到另一个字符串,但这可能是语法错误。
连接此字符串的方式意味着
tblOrderAA
和WHERE
之间不会有空格。中间添加一个空格。您还应该查找 SQL 注入/参数化查询。
I'm not sure if having two select statements in your MySQL query is valid or not, or why you're taking a string only to turn it into a number so you can add it to another string, but this is probably the cause of the syntax error.
The way you're concatenating this string means there would be no space between
tblOrderAA
andWHERE
. Add a space in between.You should also look up SQL injection/parameterized queries.
首先,即使访问支持它,您的设置方式也需要您处理不同的结果集(您必须调用 Reader.NextResult 才能从第二个 select 语句获取值。
但是,这是一个容易解决的问题:将查询分解为单独的命令,然后从您要查找的每个查询中获取一个值:
First, the way you have it setup, even if it were supported by access, would require you to process different resultset (you would have to call Reader.NextResult in order to get the values from the second select statement.
However, this is an easy problem to solve: break your queries up into separate commands and just get the one value from each query that you are looking for: