我有一个 .aspx 页面,其中包含对 informix 数据库的查询。此查询通过 odbc 连接完成并放入数据表中。然后将此数据表用作单选按钮组的数据源。
我的问题是,无论出于何种原因,时间都作为“12:00:00 AM”附加到单选按钮上。这很奇怪,因为informix 字段是不包括时间的日期字段。如果我要在网页之外运行查询,它会在没有时间的情况下返回它......“2012-06-15”
所以总而言之......我得到的是:“6/15/2012 12:00:00 AM”而我想要的是“06/15/2012”
查询如下:
"select DATE(attend_date) as attend_date from soar_major_table where major =? and active<>'N'"
创建数据表的代码:
string connString;
connString = ConfigurationManager.ConnectionStrings [ "ERP" ].ConnectionString;
OdbcConnection conn = new OdbcConnection ( );
conn.ConnectionString = connString;
string sql = "select DATE(attend_date) as attend_date from soar_major_table where major =? and active<>'N' ";
OdbcCommand command = new OdbcCommand ( );
command.CommandText = sql;
command.Parameters.Add ( new OdbcParameter ( "major", major ) );
command.Connection = conn;
DataTable dt = new DataTable ( );
OdbcDataAdapter dataAdapter = new OdbcDataAdapter ( );
dataAdapter.SelectCommand = command;
try
{
conn.Open ( );
dataAdapter.Fill ( dt );
}
finally
{
if ( conn != null && conn.State == ConnectionState.Open )
{
command.Dispose ( );
dataAdapter.Dispose ( );
conn.Close ( );
}
}
return dt;
最后是广播 btn 组的人口:
if ( dt.Rows.Count > 0 )
{
rdoDate.DataSource = dt;
rdoDate.DataTextField = "attend_date";
rdoDate.DataValueField = "attend_date";
rdoDate.DataBind ( );
}