当我从 ASP C# 调用它时,该查询不会返回值,但是当我连接 MySQL 服务器并键入相同的查询时,它会返回正确的值。我无法发现问题。
这是代码段:
try
{
personquery = "select b.* from booking b, makes m "+
"where m.personid="+
DataDeneme1.login.personid.ToString() +
"and m.bookingno=b.bookingno";
con = new MySqlConnection(System.Configuration.ConfigurationManager.AppSettings.Get("connectionString"));
cmd.CommandText = personquery;
con.Open();
cmd.Connection = con;
adap = new MySqlDataAdapter(personquery, con);
adap.Fill(ds);
// CheckBoxList1.DataSource = ds;
// CheckBoxList1.DataBind();
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
Response.Write(ex.StackTrace);
}
mysql服务器的输入和输出:
mysql> select b.* from booking b, makes m where m.personid=1 and m.bookingno=b.bookingno;
+-----------+-----------------+--------------+-------------+------------+-------------+
| bookingno | reservationdate | dropoffplace | pickupplace | pickupdate | dropoffdate |
+-----------+-----------------+--------------+-------------+------------+-------------+
| 8 | 2011-05-09 | Ankara | Ankara | 2011-05-10 | 2011-05-15 |
| 9 | 2011-05-09 | Ankara | Ankara | 2011-05-20 | 2011-05-25 |
+-----------+-----------------+--------------+-------------+------------+-------------+
2 rows in set (0.00 sec)
和异常消息....
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在 MySql.Data.MySqlClient.NativeDriver 的 MySql.Data.MySqlClient.MySqlStream.ReadPacket() 的第 1 行的“m.bookingno=b.bookingno”附近使用正确的语法。在 MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId) 在 MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32&affectedRows, Int32& insertedId) 在 MySql.Data.MySqlClient.MySqlDataReader .NextResult() 在 MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior 行为) 在 MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior 行为) 在 System.Data.Common.DbCommand.System.Data.IDbCommand。