【发布时间】:2011-08-22 01:14:47
【问题描述】:
当我从 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 和插入的 ID)在 MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId,Int32& 受影响的Rows, Int32& 插入 ID)在 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(数据集 数据集,DataTable[] 数据表,Int32 startRecord,Int32 maxRecords,字符串 srcTable,IDbCommand 命令, CommandBehavior 行为)在 System.Data.Common.DbDataAdapter.Fill(数据集 数据集,Int32 开始记录,Int32 maxRecords,字符串 srcTable, IDbCommand 命令,CommandBehavior 行为)在 System.Data.Common.DbDataAdapter.Fill(数据集 数据集)在 DataDeneme1.customerview.loadList() 在 E:\VisualStudioProjects\DataDeneme1\DataDeneme1\customerview.aspx.cs:line 38
【问题讨论】:
-
第 38 行是 --> adap.Fill(ds);
-
他得到一个 SQL 错误,所以数据集填充甚至不会发生。
标签: c# mysql gridview dataadapter