Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. datetime type field insert

datetime type field insert

Scheduled Pinned Locked Moved ASP.NET
databasehelpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    ptvce
    wrote on last edited by
    #1

    i want insert a recored in sql that one field is datetime type, i write this code but it has error , do u know why? string insertCommand = insert into Paper_Ajance (Paper_ID,Request,Paper_Date) values ('111','True',@MyParam); using (SqlConnection cnn = new SqlConnection(ConnectionString)) { using (SqlCommand cmm = new SqlCommand()) { cnn.Open(); cmm.Connection = cnn; cmm.CommandText = insertCommand; SqlParameter param = new SqlParameter(); param.ParameterName = "@MyParam"; param.Value = DateTime.Now; cmm.Parameters.Add(param); cmm.ExecuteNonQuery(); } }

    N S 2 Replies Last reply
    0
    • P ptvce

      i want insert a recored in sql that one field is datetime type, i write this code but it has error , do u know why? string insertCommand = insert into Paper_Ajance (Paper_ID,Request,Paper_Date) values ('111','True',@MyParam); using (SqlConnection cnn = new SqlConnection(ConnectionString)) { using (SqlCommand cmm = new SqlCommand()) { cnn.Open(); cmm.Connection = cnn; cmm.CommandText = insertCommand; SqlParameter param = new SqlParameter(); param.ParameterName = "@MyParam"; param.Value = DateTime.Now; cmm.Parameters.Add(param); cmm.ExecuteNonQuery(); } }

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      ptvce wrote:

      but it has error

      Don't you think telling us what the error is would be helpful? Also, please format your code snippets appropriately. Read the forum guidelines. If you following the guidelines you are more likely to receive help.


      I know the language. I've read a book. - _Madmatt

      1 Reply Last reply
      0
      • P ptvce

        i want insert a recored in sql that one field is datetime type, i write this code but it has error , do u know why? string insertCommand = insert into Paper_Ajance (Paper_ID,Request,Paper_Date) values ('111','True',@MyParam); using (SqlConnection cnn = new SqlConnection(ConnectionString)) { using (SqlCommand cmm = new SqlCommand()) { cnn.Open(); cmm.Connection = cnn; cmm.CommandText = insertCommand; SqlParameter param = new SqlParameter(); param.ParameterName = "@MyParam"; param.Value = DateTime.Now; cmm.Parameters.Add(param); cmm.ExecuteNonQuery(); } }

        S Offline
        S Offline
        Sandeep Mewara
        wrote on last edited by
        #3

        ptvce wrote:

        string insertCommand = insert into Paper_Ajance (Paper_ID,Request,Paper_Date) values ('111','True',@MyParam);

        For now, the first error in your code is - you have not put the insertCommand string in double quotes! If you read forum guidelines properly, posting your code/question correctly would get you expected response. Update your question, format it correctly, post error if you face it after using 'double quotes' around insert command string. One more thing, do try to define the Parameter type as DateTime (assuming database too has a defined Datetime field)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups