我想从MySQL领域的读取日期时间类型,我尝试了一切,始终是返回字段的名称而已。
I'm trying to read from mysql field with datetime type and I was trying everything and always it's return field name only.
下面是我的code:
using (MySqlConnection connection = new MySqlConnection(ConnectionString))
{
connection.Open();
string query = @"SELECT `sID`, 'sDate', `sGameLogin`, `dGameAmount`,
'sPayMethod' FROM `XeronRequests` WHERE `iStatus` = 0";
MySqlCommand cmd = new MySqlCommand(query, connection);
cmd.CommandType = CommandType.Text;
using (MySqlDataReader dataReader = cmd.ExecuteReader())
{
while (dataReader.Read())
{
list.Add(new PaymentInfoText(dataReader["sID"] + "",
dataReader["sDate"] + "",
dataReader["sGameLogin"] + "",
dataReader["dGameAmount"] + "",
dataReader["sPayMethod"] + ""));
}
}
e.Result = list;
}
使用
Use
而不是
dataReader["sDate"] + ""
和消除周围的列蜱在sql,如:
and remove the ticks around your columns in the sql, e.g.
SDATE
而不是SDATE
。你需要他们只为保留字,或者如果你有空格的列名:
sDate
instead of 'sDate'
. You need them only for reserved words or if you have spaces in your column names:
9.3。保留字
2.2。在MySQL中保留字5.1