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. General Programming
  3. C#
  4. insert sql

insert sql

Scheduled Pinned Locked Moved C#
databasehelpsecurityquestion
8 Posts 4 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.
  • W Offline
    W Offline
    wistiti5
    wrote on last edited by
    #1

    Hello, I have a problem with inserting into a table. I can read from it, but no updates or inserts. This is the code i wrote: string connectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Planning.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; string queryString = "INSERT INTO registratie(userid,clientid,taskid,unitid,date,start,stop,description) " + "VALUES(2,1,1,1,GETDATE(),'08:08','09:00','bla bla bal ...') "; SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(queryString, connection); try { connection.Open(); } catch (Exception ex) { MessageBox.Show(ex.Message); } try { int test = command.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { MessageBox.Show("QUERY: " + queryString + "\n inserted !!!"); connection.Close(); } Can someone please help me? thx wistiti 5

    V A A 3 Replies Last reply
    0
    • W wistiti5

      Hello, I have a problem with inserting into a table. I can read from it, but no updates or inserts. This is the code i wrote: string connectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Planning.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; string queryString = "INSERT INTO registratie(userid,clientid,taskid,unitid,date,start,stop,description) " + "VALUES(2,1,1,1,GETDATE(),'08:08','09:00','bla bla bal ...') "; SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(queryString, connection); try { connection.Open(); } catch (Exception ex) { MessageBox.Show(ex.Message); } try { int test = command.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { MessageBox.Show("QUERY: " + queryString + "\n inserted !!!"); connection.Close(); } Can someone please help me? thx wistiti 5

      V Offline
      V Offline
      V 0
      wrote on last edited by
      #2

      do you get an error message? When you look in the quickwatch: what does the 'queryString' variable have as value? Coulda, woulda, shoulda doesn't matter if you don't.

      W 1 Reply Last reply
      0
      • W wistiti5

        Hello, I have a problem with inserting into a table. I can read from it, but no updates or inserts. This is the code i wrote: string connectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Planning.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; string queryString = "INSERT INTO registratie(userid,clientid,taskid,unitid,date,start,stop,description) " + "VALUES(2,1,1,1,GETDATE(),'08:08','09:00','bla bla bal ...') "; SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(queryString, connection); try { connection.Open(); } catch (Exception ex) { MessageBox.Show(ex.Message); } try { int test = command.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { MessageBox.Show("QUERY: " + queryString + "\n inserted !!!"); connection.Close(); } Can someone please help me? thx wistiti 5

        A Offline
        A Offline
        Artur Sokhikyan
        wrote on last edited by
        #3

        May be the user via which u r connecting to db doesnt have permisions to insert or update in this table

        W 1 Reply Last reply
        0
        • V V 0

          do you get an error message? When you look in the quickwatch: what does the 'queryString' variable have as value? Coulda, woulda, shoulda doesn't matter if you don't.

          W Offline
          W Offline
          wistiti5
          wrote on last edited by
          #4

          I don't get an error message, that's the problem. I don't really understand what you mean with quickwatch, but if you mean what the output is at the end it gives: QUERY: bla bla inserted When I do this query directly with sql in the database it there is no problem. Regards William wistiti 5

          V 1 Reply Last reply
          0
          • A Artur Sokhikyan

            May be the user via which u r connecting to db doesnt have permisions to insert or update in this table

            W Offline
            W Offline
            wistiti5
            wrote on last edited by
            #5

            And how kan I solve this problem? thx wistiti 5

            V 1 Reply Last reply
            0
            • W wistiti5

              Hello, I have a problem with inserting into a table. I can read from it, but no updates or inserts. This is the code i wrote: string connectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Planning.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; string queryString = "INSERT INTO registratie(userid,clientid,taskid,unitid,date,start,stop,description) " + "VALUES(2,1,1,1,GETDATE(),'08:08','09:00','bla bla bal ...') "; SqlConnection connection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand(queryString, connection); try { connection.Open(); } catch (Exception ex) { MessageBox.Show(ex.Message); } try { int test = command.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { MessageBox.Show("QUERY: " + queryString + "\n inserted !!!"); connection.Close(); } Can someone please help me? thx wistiti 5

              A Offline
              A Offline
              albCode
              wrote on last edited by
              #6

              . . . . SqlCommand command = new SqlCommand(); command.Connection = connection ; command.CommandText = queryString; try { connection.Open(); command.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { connection.Close(); } _____________________ Proud to be Albanian _____________________

              1 Reply Last reply
              0
              • W wistiti5

                I don't get an error message, that's the problem. I don't really understand what you mean with quickwatch, but if you mean what the output is at the end it gives: QUERY: bla bla inserted When I do this query directly with sql in the database it there is no problem. Regards William wistiti 5

                V Offline
                V Offline
                V 0
                wrote on last edited by
                #7

                No what I meant was: in debug mode (set a breakpoint) If the variable is assigned hover over the variable with your cursor, right-click and choose quick watch. You'll get a dialog with some info. The cool thing about quickwatch is that you can alter the data or see entire objects. Coulda, woulda, shoulda doesn't matter if you don't.

                1 Reply Last reply
                0
                • W wistiti5

                  And how kan I solve this problem? thx wistiti 5

                  V Offline
                  V Offline
                  V 0
                  wrote on last edited by
                  #8

                  Don't know the syntax, but you can look it op on google (try looking on GRANT, ALTER USER, ...) good luck. Coulda, woulda, shoulda doesn't matter if you don't.

                  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