Hi
I used executenonquery to insert values in database.
after running the code,i am getting duplicate rows inserted in the table.
SqlCommand sqlcmd = new SqlCommand("select max(UNo) as UNo from USERDETAILS", sqlconn1);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(sqlcmd);
da.Fill(ds);
int maxUNo = 1;
if (ds.Tables != null && ds.Tables.Count > 0 && !string.IsNullOrEmpty(ds.Tables[0].Rows[0][0].ToString()))
{
maxUNo = Int32.Parse(ds.Tables[0].Rows[0][0].ToString()) + 1;
}
int IsActive = chkIsActive.Checked ? 1 : 0;
string strQtyString = "INSERT INTO USERDETAILS(UNo,EmployeeID,EmployeeName,UserName,"
+ " Password,EmailAddress,IsActive)"
+ " VALUES(" + maxUNo + ",'" + txtEmployeeID.Text + "','" + txtEmpName.Text + "','" + txtUserName.Text + "','" + txtPassword.Text + "',"
+ " '" + txtEmail.Text + "'," + IsActive + ")";
SqlCommand Sqlcmd = new SqlCommand(strQtyString, sqlconn1);
Sqlcmd.CommandType = CommandType.Text;
int res= Sqlcmd.ExecuteNonQuery();
SqlCommand Sqlcmd = new SqlCommand(sqlQry, sqlconn1);
int res= Sqlcmd.ExecuteNonQuery();
database structure
CREATE TABLE [dbo].[USERDETAILS](
[UNo] [int] NOT NULL,//primary key
[EmployeeID] [varchar](100) NOT NULL,
[EmployeeName] [varchar](100) NOT NULL,
[UserName] [varchar](50) NOT NULL,
[Password] [varchar](50) NULL,
[EmailAddress] [varchar](50) NOT NULL,
[IsActive] [int] NULL,
Thanks
chandran