M
Mike
I know this sounds strange but I am at a loss. I am calling a simple
funtion that opens a connection to a SQL Server 2000 database and executes
an Insert Statement.
private void AddMinimunWageStipen(string payrollid,double amount)
{
System.Data.SqlClient.SqlConnection cn = null;
System.Data.SqlClient.SqlCommand cm = null;
string sql = "INSERT INTO tblStipen (EmployeeID, StipenTypeID, Units,
Amount, AddHours, PayrollID) ";
sql+= "VALUES (" + _employeeid + ", 3, 1, " + amount + ", 0, " + payrollid
+ ")";
try
{
cn = new
System.Data.SqlClient.SqlConnection(PayrollSystem.Data.SQLSERVER);
cn.Open();
cm = new System.Data.SqlClient.SqlCommand(sql,cn);
int flag = cm.ExecuteNonQuery();
cn.Close();
}
catch(Exception ex)
{
throw ex;
}
finally
{
cm.Dispose();
cn.Dispose();
}
}
When I run this code in the debugger and step through this funtion, when I
execute the line "int flag = cm.ExecuteNonQuery();" the Insert Statement
gets exectued 3 times. So I have the same record in the database 3 times??
And I know the the code is only being exectuted once. The function isn't
being called 3 times with the same parameters being passed in. I am also
not doing any special threading.
If I run the program without stopping in this function the code behave like
it should and the record only gets inserted once.
Is there something I am missing? Has anyone else ran into this problem?
Thanks in advance,
Mike R
funtion that opens a connection to a SQL Server 2000 database and executes
an Insert Statement.
private void AddMinimunWageStipen(string payrollid,double amount)
{
System.Data.SqlClient.SqlConnection cn = null;
System.Data.SqlClient.SqlCommand cm = null;
string sql = "INSERT INTO tblStipen (EmployeeID, StipenTypeID, Units,
Amount, AddHours, PayrollID) ";
sql+= "VALUES (" + _employeeid + ", 3, 1, " + amount + ", 0, " + payrollid
+ ")";
try
{
cn = new
System.Data.SqlClient.SqlConnection(PayrollSystem.Data.SQLSERVER);
cn.Open();
cm = new System.Data.SqlClient.SqlCommand(sql,cn);
int flag = cm.ExecuteNonQuery();
cn.Close();
}
catch(Exception ex)
{
throw ex;
}
finally
{
cm.Dispose();
cn.Dispose();
}
}
When I run this code in the debugger and step through this funtion, when I
execute the line "int flag = cm.ExecuteNonQuery();" the Insert Statement
gets exectued 3 times. So I have the same record in the database 3 times??
And I know the the code is only being exectuted once. The function isn't
being called 3 times with the same parameters being passed in. I am also
not doing any special threading.
If I run the program without stopping in this function the code behave like
it should and the record only gets inserted once.
Is there something I am missing? Has anyone else ran into this problem?
Thanks in advance,
Mike R