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. Database & SysAdmin
  3. Database
  4. My SQl error while sending to database

My SQl error while sending to database

Scheduled Pinned Locked Moved Database
databasehelpquestion
6 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.
  • I Offline
    I Offline
    Inderjeet Kaur
    wrote on last edited by
    #1

    Hi string conn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; MySqlConnection con = new MySqlConnection(conn); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = con; cmd.CommandText = "Insert_Image"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("?description", SqlDbType.VarChar).Value = txtdesc.Text; cmd.Parameters.AddWithValue("?fullstr", SqlDbType.VarChar).Value = path; con.Open(); cmd.ExecuteNonQuery(); cmd.Connection.Close(); Session.RemoveAll(); My code is giving error at executenonquery, "Input string not in correct format". The values in path and txt dec are correct. Can you please tell where i am wrong? Regards Inderjeet Kaur Inderjeet Kaur Sr. Software Engg

    L P 2 Replies Last reply
    0
    • I Inderjeet Kaur

      Hi string conn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; MySqlConnection con = new MySqlConnection(conn); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = con; cmd.CommandText = "Insert_Image"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("?description", SqlDbType.VarChar).Value = txtdesc.Text; cmd.Parameters.AddWithValue("?fullstr", SqlDbType.VarChar).Value = path; con.Open(); cmd.ExecuteNonQuery(); cmd.Connection.Close(); Session.RemoveAll(); My code is giving error at executenonquery, "Input string not in correct format". The values in path and txt dec are correct. Can you please tell where i am wrong? Regards Inderjeet Kaur Inderjeet Kaur Sr. Software Engg

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      The AddWithValue method expects the actual value to be passed rather than the data types, so you should write something like:

      cmd.Parameters.AddWithValue("?description", txtdesc.Text);

      I 1 Reply Last reply
      0
      • L Lost User

        The AddWithValue method expects the actual value to be passed rather than the data types, so you should write something like:

        cmd.Parameters.AddWithValue("?description", txtdesc.Text);

        I Offline
        I Offline
        Inderjeet Kaur
        wrote on last edited by
        #3

        Thanks alot! I am new to MY SQL database and my problem is solved. Inderjeet Kaur Sr. Software Engg

        L 1 Reply Last reply
        0
        • I Inderjeet Kaur

          Thanks alot! I am new to MY SQL database and my problem is solved. Inderjeet Kaur Sr. Software Engg

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          You're welcome. However, this problem isn't related to My SQL in any way, rather it is to do with ADO.NET.

          1 Reply Last reply
          0
          • I Inderjeet Kaur

            Hi string conn = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; MySqlConnection con = new MySqlConnection(conn); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = con; cmd.CommandText = "Insert_Image"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("?description", SqlDbType.VarChar).Value = txtdesc.Text; cmd.Parameters.AddWithValue("?fullstr", SqlDbType.VarChar).Value = path; con.Open(); cmd.ExecuteNonQuery(); cmd.Connection.Close(); Session.RemoveAll(); My code is giving error at executenonquery, "Input string not in correct format". The values in path and txt dec are correct. Can you please tell where i am wrong? Regards Inderjeet Kaur Inderjeet Kaur Sr. Software Engg

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            When I use MySQL I use an at (@), not a question mark (?) -- I thought that was the problem, does it work with the question mark?

            L 1 Reply Last reply
            0
            • P PIEBALDconsult

              When I use MySQL I use an at (@), not a question mark (?) -- I thought that was the problem, does it work with the question mark?

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Dunno, but it works without any mark too. I only use the @-sign within the Sql-statement, the AddWithValue method always without.

              Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

              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