<asp:FormView>   
   <InsertItemTemplate>
   <table>
    <td>
     <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Date") %>'></asp:TextBox> 
     <asp:LinkButton ID="LinkButton1" runat="server" 
      onclick="LinkButton1_Click" CommandName="Insert">保存</asp:LinkButton>
    </td>
   </table>
  </InsertItemTemplate>
</asp:FormView>
 <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
            InsertCommand="INSERT INTO CompanyNews(Name, TheContent, Date) VALUES (@Name, @TheContent, @Date)" 
            <InsertParameters>
                <asp:Parameter Name="Name" />
                <asp:Parameter Name="TheContent" />
                <asp:Parameter Name="Date" />
            </InsertParameters>
</asp:SqlDataSource>点击按钮的时候会报错。按钮直接选了CommandName="Insert";如何把Bind("Date")变成DateTime插入数据库?

解决方案 »

  1.   

    <%# Convert.ToDateTime(Bind("Date"))%>或者<%#DateTime.Parse(Bind("Date"))%>
      

  2.   

    你何不直接用数据库时间呢,在数据库时间字段用默认值 GETDATE()
      

  3.   

    将数据库表CompanyNews中的Date字段设上默认值getdate()这样你就不需要进行插入了,自己操作还方便,是不是?
      

  4.   

    将数据库表CompanyNews中的Date字段原本就是getdate() 啊。。Bind("Date")这个东西是字符串,要转换成DateTime