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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. [Message Deleted]

[Message Deleted]

Scheduled Pinned Locked Moved C#
28 Posts 5 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.
  • V Offline
    V Offline
    Vivek Vijayan
    wrote on last edited by
    #1

    [Message Deleted]

    M I V M 4 Replies Last reply
    0
    • V Vivek Vijayan

      [Message Deleted]

      M Offline
      M Offline
      moon_stick
      wrote on last edited by
      #2

      Doesn't work why? Do you have an exception? An error message from the database? Does the user you've connected to the database as have insert permissions? Is your query string correctly formatted? Is your getconnection() method returning an object correctly? Is there a specific line where the error occurs?

      It definitely isn't definatley

      V 1 Reply Last reply
      0
      • V Vivek Vijayan

        [Message Deleted]

        I Offline
        I Offline
        Ian Shlasko
        wrote on last edited by
        #3

        If you want a meaningful response, you're going to have to be a lot more specific. What exception are you getting? What line is triggering it? What query are you sending? We're programmers, not psychics.

        Proud to have finally moved to the A-Ark. Which one are you in? Developer, Author (Guardians of Xen)

        V 1 Reply Last reply
        0
        • V Vivek Vijayan

          [Message Deleted]

          V Offline
          V Offline
          Vimalsoft Pty Ltd
          wrote on last edited by
          #4

          Good Day Vivek Today was a long day, and seing this kind of post in the forums bores me to death. First of all when you post something here on codeproject you must use the pre tags so that the code will be formated well and it can differ from your message. secondly we cant know the problem until we see what is contained in the variable "query" , and another thing there is a bad coding practise in your code, you start returning without closing the connection.

          Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.somee.com http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

          V 1 Reply Last reply
          0
          • V Vivek Vijayan

            [Message Deleted]

            M Offline
            M Offline
            musefan
            wrote on last edited by
            #5

            I would say you have a compile error for no catch/finally block but that's the best I can give you for the example you have shown... Oh, no wait... it's coming to me... 'the.. answer.. is.. .. ..' ..Damn, lost it!

            Life goes very fast. Tomorrow, today is already yesterday.

            V 1 Reply Last reply
            0
            • V Vimalsoft Pty Ltd

              Good Day Vivek Today was a long day, and seing this kind of post in the forums bores me to death. First of all when you post something here on codeproject you must use the pre tags so that the code will be formated well and it can differ from your message. secondly we cant know the problem until we see what is contained in the variable "query" , and another thing there is a bad coding practise in your code, you start returning without closing the connection.

              Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.somee.com http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

              V Offline
              V Offline
              Vivek Vijayan
              wrote on last edited by
              #6

              i don feel that pasting the code for close is necessary....

              This code was posted by me...

              V M 2 Replies Last reply
              0
              • M moon_stick

                Doesn't work why? Do you have an exception? An error message from the database? Does the user you've connected to the database as have insert permissions? Is your query string correctly formatted? Is your getconnection() method returning an object correctly? Is there a specific line where the error occurs?

                It definitely isn't definatley

                V Offline
                V Offline
                Vivek Vijayan
                wrote on last edited by
                #7

                not exception is caught insert query is String query = "insert into mydb values('" + textBox1.Text + "','" + textBox2.Text + "')";

                This code was posted by me...

                I M 2 Replies Last reply
                0
                • V Vivek Vijayan

                  i don feel that pasting the code for close is necessary....

                  This code was posted by me...

                  V Offline
                  V Offline
                  Vimalsoft Pty Ltd
                  wrote on last edited by
                  #8

                  Then i cant help

                  Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.somee.com http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

                  V 1 Reply Last reply
                  0
                  • I Ian Shlasko

                    If you want a meaningful response, you're going to have to be a lot more specific. What exception are you getting? What line is triggering it? What query are you sending? We're programmers, not psychics.

                    Proud to have finally moved to the A-Ark. Which one are you in? Developer, Author (Guardians of Xen)

                    V Offline
                    V Offline
                    Vivek Vijayan
                    wrote on last edited by
                    #9

                    no exception is caught insert query is String query = "insert into mydb values('" + textBox1.Text + "','" + textBox2.Text + "')";

                    This code was posted by me...

                    1 Reply Last reply
                    0
                    • V Vimalsoft Pty Ltd

                      Then i cant help

                      Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.somee.com http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

                      V Offline
                      V Offline
                      Vivek Vijayan
                      wrote on last edited by
                      #10

                      no need tnx

                      This code was posted by me...

                      1 Reply Last reply
                      0
                      • M musefan

                        I would say you have a compile error for no catch/finally block but that's the best I can give you for the example you have shown... Oh, no wait... it's coming to me... 'the.. answer.. is.. .. ..' ..Damn, lost it!

                        Life goes very fast. Tomorrow, today is already yesterday.

                        V Offline
                        V Offline
                        Vivek Vijayan
                        wrote on last edited by
                        #11

                        if i am writing code for try{} i know how to write catch and finally tnx

                        This code was posted by me...

                        M 1 Reply Last reply
                        0
                        • V Vivek Vijayan

                          not exception is caught insert query is String query = "insert into mydb values('" + textBox1.Text + "','" + textBox2.Text + "')";

                          This code was posted by me...

                          I Offline
                          I Offline
                          Ian Shlasko
                          wrote on last edited by
                          #12

                          I notice you're using a try block, but I don't see the catch... Are you sure you're not just throwing away the exception? And if there's really no exception, try setting a breakpoint and seeing exactly what "query" is being set to after that line runs. Maybe your textboxes are blank. If the query is right, and you're really getting no exception, then it might be a database issue... Try running the exact query (Copy-paste it, so you know it's the same) in an SQL client to see what happens. EDIT: Oops, responded to the wrong identical reply...

                          Proud to have finally moved to the A-Ark. Which one are you in? Developer, Author (Guardians of Xen)

                          V 1 Reply Last reply
                          0
                          • I Ian Shlasko

                            I notice you're using a try block, but I don't see the catch... Are you sure you're not just throwing away the exception? And if there's really no exception, try setting a breakpoint and seeing exactly what "query" is being set to after that line runs. Maybe your textboxes are blank. If the query is right, and you're really getting no exception, then it might be a database issue... Try running the exact query (Copy-paste it, so you know it's the same) in an SQL client to see what happens. EDIT: Oops, responded to the wrong identical reply...

                            Proud to have finally moved to the A-Ark. Which one are you in? Developer, Author (Guardians of Xen)

                            V Offline
                            V Offline
                            Vivek Vijayan
                            wrote on last edited by
                            #13

                            SqlConnection con = connection(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = query; cmd.Connection = con; try { con.Open(); cmd.ExecuteNonQuery(); return 1; } catch (Exception e) { return 0; } finally { con.Close(); cmd.Dispose(); } tis is the code its running fine without exception but no data is inserted into the table at last

                            This code was posted by me...

                            M M 2 Replies Last reply
                            0
                            • V Vivek Vijayan

                              not exception is caught insert query is String query = "insert into mydb values('" + textBox1.Text + "','" + textBox2.Text + "')";

                              This code was posted by me...

                              M Offline
                              M Offline
                              moon_stick
                              wrote on last edited by
                              #14

                              With regards to the query, I meant the actual string value that is being passed to the database, rather than the statement you use to construct it. Incidentally, is 'mydb' the name of the table or the name of a database containing the table (i.e. should it actually be "insert into mydb.dbo.mytable..."?). What about the rest of the questions I asked? Have you tried running a profiler on the database to see if the query is actually received. Does the c# statement actually exectute?

                              It definitely isn't definatley

                              V 1 Reply Last reply
                              0
                              • V Vivek Vijayan

                                if i am writing code for try{} i know how to write catch and finally tnx

                                This code was posted by me...

                                M Offline
                                M Offline
                                musefan
                                wrote on last edited by
                                #15

                                Vivek Vijayan wrote:

                                if i am writing code for try{} i know how to write catch and finally

                                Er... Where is the logic in that? you are writing code for database insert but that evidently does not mean you know how to write it And it's a good example of why your need to make your example better in order to get a good response - you didn't put the catch/finally in your example so how do I know that is not your error?! Hmmm... a little thought can go a long way.

                                Life goes very fast. Tomorrow, today is already yesterday.

                                1 Reply Last reply
                                0
                                • V Vivek Vijayan

                                  SqlConnection con = connection(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = query; cmd.Connection = con; try { con.Open(); cmd.ExecuteNonQuery(); return 1; } catch (Exception e) { return 0; } finally { con.Close(); cmd.Dispose(); } tis is the code its running fine without exception but no data is inserted into the table at last

                                  This code was posted by me...

                                  M Offline
                                  M Offline
                                  musefan
                                  wrote on last edited by
                                  #16

                                  Obviously there is no exception that what a try catch does, it enables you to handle the exception, you catch is returning 0 so your not going to see any problem. You may have a problem with your insert statement too, have your tried specifying the columns you are trying to add data to?

                                  Life goes very fast. Tomorrow, today is already yesterday.

                                  V 1 Reply Last reply
                                  0
                                  • V Vivek Vijayan

                                    SqlConnection con = connection(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = query; cmd.Connection = con; try { con.Open(); cmd.ExecuteNonQuery(); return 1; } catch (Exception e) { return 0; } finally { con.Close(); cmd.Dispose(); } tis is the code its running fine without exception but no data is inserted into the table at last

                                    This code was posted by me...

                                    M Offline
                                    M Offline
                                    moon_stick
                                    wrote on last edited by
                                    #17

                                    What values does this method return? You're catching the exception but not doing anything with it (apart from changing the return value). Assuming you're using VS, set a breakpoint on the line "return 0;" and check to see that the value of 'e' (the exception) is.

                                    It definitely isn't definatley

                                    V 1 Reply Last reply
                                    0
                                    • M moon_stick

                                      With regards to the query, I meant the actual string value that is being passed to the database, rather than the statement you use to construct it. Incidentally, is 'mydb' the name of the table or the name of a database containing the table (i.e. should it actually be "insert into mydb.dbo.mytable..."?). What about the rest of the questions I asked? Have you tried running a profiler on the database to see if the query is actually received. Does the c# statement actually exectute?

                                      It definitely isn't definatley

                                      V Offline
                                      V Offline
                                      Vivek Vijayan
                                      wrote on last edited by
                                      #18

                                      no exception is caught i don knwo where is the problem what is the meaning of this "Have you tried running a profiler on the database to see if the query is actually received. "

                                      This code was posted by me...

                                      M 1 Reply Last reply
                                      0
                                      • V Vivek Vijayan

                                        i don feel that pasting the code for close is necessary....

                                        This code was posted by me...

                                        M Offline
                                        M Offline
                                        musefan
                                        wrote on last edited by
                                        #19

                                        Vivek Vijayan wrote:

                                        i don feel that pasting the code for close is necessary....

                                        Your right, it is not necessary... when you provide a better description of what the problem is. But as everyone is having to guess how bad your code is, people are going to ask questions.

                                        Life goes very fast. Tomorrow, today is already yesterday.

                                        V 1 Reply Last reply
                                        0
                                        • V Vivek Vijayan

                                          no exception is caught i don knwo where is the problem what is the meaning of this "Have you tried running a profiler on the database to see if the query is actually received. "

                                          This code was posted by me...

                                          M Offline
                                          M Offline
                                          moon_stick
                                          wrote on last edited by
                                          #20

                                          A database profiler is a tool which monitors a database and reports back when certain events occur, such as connections to the database, queries, triggers etc. SQL Server comes with its own profiler called (originally enough) SQL Server Profiler - I don't tend to use other databases but I'm sure there are similar tools available for other platforms.

                                          It definitely isn't definatley

                                          V 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