我用数据适配器 DataAdapter.fill(dataset), 数据库中某列为datetime型,精确到毫秒,但是用fill方法加载到datatable里面后,精确到了秒,怎么样才能精确到毫秒呢??

解决方案 »

  1.   

    数据已经在datatable里面了,是精确到毫秒的,但是fill方法加载到datatable里面后,毫秒被省略了,精确到了秒,有什么方法可以不省略毫秒
      

  2.   

    数据已经在数据库的表里面了,是精确到毫秒的,但是fill方法加载到datatable里面后,毫秒被省略了,精确到了秒,有什么方法可以不省略毫秒
      

  3.   

     public DataTable GetDate(string where)
            {
                SqlConnection cn = new SqlConnection();
                cn.ConnectionString = "";
                SqlCommand cmd = new SqlCommand();
                DataTable dt = new DataTable();
                SqlDataReader dr = null;
                cmd.CommandText = where;
                cmd.Connection = cn;
                using (dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    dt.Load(dr);
                }
                if (dt.Rows.Count != 0)
                {
                    return dt;
                }
                else
                {
                    return null;
                }
            }用这种看看
      

  4.   

    先new一个DataTable,定义表结构,其中时间这一列设置类型为String。然后用数据阅读器读出数据,循环插入记录到DataTable中,注意时间这列的值要转换为String,用ToString()方法试试。
      

  5.   

    有什么爽快一点的方法,凭什么数据库里面是精确到毫秒,fill出来就精确到秒了
      

  6.   

    你直接看数据库的话它是只显示到秒
    不过你通过select出来还是可以看到毫秒的,你可以绑定后在把格式转换下,显示毫秒就可以显示出来了create table ceshi([id] int,[time] datetime)
    select getdate()--2011-02-17 15:03:06.733--
    insert into ceshi([id],[time]) values(2,convert(datetime,'2011-02-17 15:03:06.733'))
    select * from ceshi
    /*
    查询出的结果
    1 2011-02-17 15:03:39.123
    2 2011-02-17 15:03:06.733
    */
    <asp:Repeater ID="Repeater1" runat="server">
            <HeaderTemplate><table></HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td><%#Eval("ID") %></td>
                    <td><%#Eval("Time","{0:yyyy-MM-dd HH:mm:ss:fff}") %></td>
                </tr>
            </ItemTemplate>
            <FooterTemplate></table></FooterTemplate>
            </asp:Repeater>    public void Bind()
        {
            using(SqlConnection conn = new SqlConnection(@"..."))
            {
                conn.Open();
                string str = "select * from ceshi";
                DataTable dt = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(str, conn);
                da.Fill(dt);
                Repeater1.DataSource = dt;
                Repeater1.DataBind();
            }
        }
      

  7.   

    ToString("yyyy-MM-dd HH:mm:ss.fff") 
    convert(verchar(100),getdate(),121)就把毫秒存入了记录