i am trying to insert some records using C#.net to sql server 2005 database...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mohamed aurif
    New Member
    • Jan 2010
    • 1

    i am trying to insert some records using C#.net to sql server 2005 database...

    it is not inserted ...the code is as follows


    Code:
    try
    {
    con = new SqlConnection(@"Data Source=.\SQLExpress;Integrated Security=SSPI;AttachDBFilename=C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\pmsdb.mdf");
    com = new SqlCommand("insert into initialdetails values('" + txtFName.Text + "','" + txtLName.Text + "'," + txtAge.Text + ",con");
                 con.Open();
                 textBox1.Text= "Successfully added";
                
                }
                catch (Exception ex)
                {
                 textBox1.Text = ex.Message;
                }

    is there any wrong with this code?...or..any other better coding rather than this

    regards
    mohamed aurif
    Last edited by tlhintoq; Jan 25 '10, 03:46 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Database How-to parts 1 and 2
      Database tutorial Part 1
      Database tutorial Part 2

      Comment

      • Curtis Rutland
        Recognized Expert Specialist
        • Apr 2008
        • 3264

        #4
        The problem is that you never execute your command.

        Read through the database articles that tlhintoq posted, and always remember to close your open connections.

        Comment

        Working...