hi
I am trying to insert random values to the tables.
I will get no.of records value from user, based on that
loop will start to insert records. For this insertion i am
using stored procedure. I am using Transaction for each
insert statement. But when i try to insert it is
displaying "use of unassigned local
variable 'InsertTrans'. Can anybody help me.
My code is as follows.
SqlTransaction InsertTrans;
DateTime Start = DateTime.Now;
DateTime End;
Random iDepartno = new Random();
Random iJobCode = new Random();
Random iExperience = new Random();
EmployeeCommand .Connection = EmployeeConnect ion;
EmployeeCommand .CommandType = CommandType.Sto redProcedure;
EmployeeCommand .CommandText = "InsertEmployee Dtl";
EmployeeCommand .Transaction = InsertTrans;
SqlParameter FName,LName,Dat ej,DB,Dptno,Gra de, JCode ;
FName = new SqlParameter("@ FName", SqlDbType.NVarC har, 50);
FName.Direction = ParameterDirect ion.Input;
LName = new SqlParameter("@ LName", SqlDbType.NVarC har, 50);
LName.Direction = ParameterDirect ion.Input;
..
..
..
EmployeeCommand .Parameters.Add (FName);
EmployeeCommand .Parameters.Add (LName);
..
..
..
for (int iInsertRecord = 0; iInsertRecord !=
System.Int32.Pa rse(txtInsert.T ext); iInsertRecord++ )
{
try
{
EmployeeCommand .Parameters["@FName"].Value
= "Firstname" + iInsertRecord;
EmployeeCommand .Parameters["@LName"].Value = "Lastname" +
iInsertRecord;
...
...
EmployeeConnect ion.Open();
InsertTrans= EmployeeConnect ion.BeginTransa ction
(IsolationLevel .ReadCommitted) ;
EmployeeCommand .ExecuteNonQuer y();
InsertTrans.Com mit();
}
catch (SqlException sqlerr)
{
InsertTrans.Rol lback();
EmployeeConnect ion.Close();
EmployeeConnect ion.Dispose();
Response.Write (sqlerr.ToStrin g());
}
finally
{
EmployeeConnect ion.Close();
}
Thanks,
Ramesh
I am trying to insert random values to the tables.
I will get no.of records value from user, based on that
loop will start to insert records. For this insertion i am
using stored procedure. I am using Transaction for each
insert statement. But when i try to insert it is
displaying "use of unassigned local
variable 'InsertTrans'. Can anybody help me.
My code is as follows.
SqlTransaction InsertTrans;
DateTime Start = DateTime.Now;
DateTime End;
Random iDepartno = new Random();
Random iJobCode = new Random();
Random iExperience = new Random();
EmployeeCommand .Connection = EmployeeConnect ion;
EmployeeCommand .CommandType = CommandType.Sto redProcedure;
EmployeeCommand .CommandText = "InsertEmployee Dtl";
EmployeeCommand .Transaction = InsertTrans;
SqlParameter FName,LName,Dat ej,DB,Dptno,Gra de, JCode ;
FName = new SqlParameter("@ FName", SqlDbType.NVarC har, 50);
FName.Direction = ParameterDirect ion.Input;
LName = new SqlParameter("@ LName", SqlDbType.NVarC har, 50);
LName.Direction = ParameterDirect ion.Input;
..
..
..
EmployeeCommand .Parameters.Add (FName);
EmployeeCommand .Parameters.Add (LName);
..
..
..
for (int iInsertRecord = 0; iInsertRecord !=
System.Int32.Pa rse(txtInsert.T ext); iInsertRecord++ )
{
try
{
EmployeeCommand .Parameters["@FName"].Value
= "Firstname" + iInsertRecord;
EmployeeCommand .Parameters["@LName"].Value = "Lastname" +
iInsertRecord;
...
...
EmployeeConnect ion.Open();
InsertTrans= EmployeeConnect ion.BeginTransa ction
(IsolationLevel .ReadCommitted) ;
EmployeeCommand .ExecuteNonQuer y();
InsertTrans.Com mit();
}
catch (SqlException sqlerr)
{
InsertTrans.Rol lback();
EmployeeConnect ion.Close();
EmployeeConnect ion.Dispose();
Response.Write (sqlerr.ToStrin g());
}
finally
{
EmployeeConnect ion.Close();
}
Thanks,
Ramesh
Comment