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. Insertion Problem into Database

Insertion Problem into Database

Scheduled Pinned Locked Moved ASP.NET
helpdatabasecsharpcomquestion
5 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.
  • Z Offline
    Z Offline
    Zafar A khan
    wrote on last edited by
    #1

    hi everyone. i am inserting values in the table the code. SqlCommand com=new SqlCommand(); con.Open(); com.CommandText="insert into tbl([Name],FName,Address) values('Angelina','Carlos','sedny')"; com.Connection=con; com.ExecuteNonQuery(); con.Close(); This code is running perfectly no Exception occurs no Error. it is also returning the rows effected. But after successful execution the values are not inserting in the database. and when i run the same query in QueryAnalyzer it is ok and inserting the values but from the Ado.Net it is not working. i don't understand this problem. can anyone help me in this regard? thanks in advance.

    A V 2 Replies Last reply
    0
    • Z Zafar A khan

      hi everyone. i am inserting values in the table the code. SqlCommand com=new SqlCommand(); con.Open(); com.CommandText="insert into tbl([Name],FName,Address) values('Angelina','Carlos','sedny')"; com.Connection=con; com.ExecuteNonQuery(); con.Close(); This code is running perfectly no Exception occurs no Error. it is also returning the rows effected. But after successful execution the values are not inserting in the database. and when i run the same query in QueryAnalyzer it is ok and inserting the values but from the Ado.Net it is not working. i don't understand this problem. can anyone help me in this regard? thanks in advance.

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      Reconfirm if the connectionstring is perfect. I think it is inserting in some other database ... If ADO.NET cannot insert in database, it will throw you an error. ;P

      Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


      My Latest Articles-->** Windows7 API Code Pack
      Simplify Code Using NDepend
      Basics of Bing Search API using .NET

      Z 1 Reply Last reply
      0
      • A Abhishek Sur

        Reconfirm if the connectionstring is perfect. I think it is inserting in some other database ... If ADO.NET cannot insert in database, it will throw you an error. ;P

        Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.


        My Latest Articles-->** Windows7 API Code Pack
        Simplify Code Using NDepend
        Basics of Bing Search API using .NET

        Z Offline
        Z Offline
        Zafar A khan
        wrote on last edited by
        #3

        sir thank you for your reply i have checked the connectionstring it is ok. and i have no other database with same name and table, columns only the select query work. nor update and nor delete and nor insert work.

        S 1 Reply Last reply
        0
        • Z Zafar A khan

          sir thank you for your reply i have checked the connectionstring it is ok. and i have no other database with same name and table, columns only the select query work. nor update and nor delete and nor insert work.

          S Offline
          S Offline
          sri_3464 0
          wrote on last edited by
          #4

          Try inserting the data inside the transaction and commit the transaction in .net code

          modified on Wednesday, December 30, 2009 12:48 PM

          1 Reply Last reply
          0
          • Z Zafar A khan

            hi everyone. i am inserting values in the table the code. SqlCommand com=new SqlCommand(); con.Open(); com.CommandText="insert into tbl([Name],FName,Address) values('Angelina','Carlos','sedny')"; com.Connection=con; com.ExecuteNonQuery(); con.Close(); This code is running perfectly no Exception occurs no Error. it is also returning the rows effected. But after successful execution the values are not inserting in the database. and when i run the same query in QueryAnalyzer it is ok and inserting the values but from the Ado.Net it is not working. i don't understand this problem. can anyone help me in this regard? thanks in advance.

            V Offline
            V Offline
            Venkatesh Mookkan
            wrote on last edited by
            #5

            Put a breakpoint in the con.Open() line and check the connection string property of connection object. Sometimes the connection string itself referring a wrong location. As the other user said, ADO.NET will throw error if the execute fails. So, you must me referring a wrong database.

            Zafar Ali Khan 1900 wrote:

            com.CommandText="insert into <DATABASENAME>.dbo.tbl([Name],FName,Address) values('Angelina','Carlos','sedny')";

            replace the <DATABASENAME> with your database name (Full qualifier name). This would help if two or more databases has table in same name and your connection string does not have any Initial Catalog mentioned (default is master database). Better you post your connection string also

            Castle Rider

            What if I freeze??? Don't forget to breath...

            My: Website | Yahoo Group | Blog Spot

            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