Insert values into database from ASP.NET page

Apr 14 2010 1:13 AM
Hi Guys,

Here I am facing a problem to insert values into database.
In my database already 2 rows is there, but now I wanted to put from asp.net page.
but at last when I give the value it will take automatically first record only,
and give error like "Primary Key can not be duplicate........"
   
In my code I am doing like that.............


Please help me what can I do ..............?


My  Code is .......

try
        {
            if (Page.IsPostBack)
            {
               
                string InsertString = "Insert into Emp" + "(ID, Name, Designation, TempAddress, PermanentAddress, Salary, Contact)" +
                                       "values('" + txtEmpId.Text + "','" + txtName.Text + "','" + txtDesignation.Text + "','" + txtPAddress.Text + "','" + txtTaddress.Text + "','" + txtSalary.Text + "','" + txtContact.Text + "')";

               


                if (txtEmpId.Text != "" && txtName.Text != "" && txtDesignation.Text != "" && txtPAddress.Text != "" && txtTaddress.Text != "" && txtSalary.Text != "" && txtContact.Text != "")
                {

                    SqlCommand command = new SqlCommand(InsertString, objcConnect.con);
                    objcConnect.dAdapEmp.InsertCommand = command;
                    objcConnect.dAdapEmp.InsertCommand.ExecuteNonQuery();
                    //command.ExecuteNonQuery();

                    MessageBox.Show("Value Inserted");

                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
        }
 

Answers (5)