mysql查询datagridview c#

| 当我从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服务器版本   在附近使用正确的语法   \'m.bookingno = b.bookingno \'在第1行   MySql.Data.MySqlClient.MySqlStream.ReadPacket()   在   MySql.Data.MySqlClient.NativeDriver.GetResult(Int32&   受影响的行,Int32和insertId)   MySql.Data.MySqlClient.Driver.GetResult(Int32   statementId,Int32&受影响的行,   Int32&insertId)   MySql.Data.MySqlClient.Driver.NextResult(Int32   statementId)   MySql.Data.MySqlClient.MySqlDataReader.NextResult()   在   MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior   行为)   MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior   行为)   System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior   行为)   System.Data.Common.DbDataAdapter.FillInternal(DataSet   数据集,DataTable []数据表,Int32   startRecord,Int32 maxRecords,字符串   srcTable,IDbCommand命令,   CommandBehavior行为)   System.Data.Common.DbDataAdapter.Fill(数据集   dataSet,Int32 startRecord,Int32   maxRecords,字符串srcTable,   IDbCommand命令,CommandBehavior   行为)   System.Data.Common.DbDataAdapter.Fill(数据集   dataSet)   中的DataDeneme1.customerview.loadList()   E:\\ VisualStudioProjects \\ DataDeneme1 \\ DataDeneme1 \\ customerview.aspx.cs:line   38     
已邀请:
我敢打赌它与动态值
DataDeneme1.login.personid.ToString()
有关,因为异常指出了下一段文本。确保您的值与预期的一样,空格/空白值会导致此错误。 更新 根据您的评论,我看到了我认为是问题所在。如果值为
1
,则结果为:
personquery = \"select b.* from booking b, makes m  \"+
              \"where m.personid=\"+ 
              DataDeneme1.login.personid.ToString() +
              \"and m.bookingno=b.bookingno\";
将会:
select b.* from booking b, makes m
where m.personid=1and m.bookingno=b.bookingno
没有空间,因此将其添加到初始查询创建中:
personquery = \"select b.* from booking b, makes m  \"+
              \"where m.personid= \"+ 
              DataDeneme1.login.personid.ToString() +
              \" and m.bookingno=b.bookingno\";
这将导致:
select b.* from booking b, makes m
where m.personid= 1 and m.bookingno=b.bookingno
    
确保\“和m.bookingno = b.bookingno \”中有空格。我的意思是在“和”之前,例如“和”。     

要回复问题请先登录注册