S
sippyuconn
Hi
I have the code working - just want to make sure it is being coded correctly
I need to run thru a loop to insert multiple records thru Method
AddAuditMasterRecord
I have the OleDBCommand setup and was wondering if I am initializing it
correctly and doing cleanup to optimize performance
1)Should I run cmdMaster.Parameters.Clear(); after each call to
cmdMaster.ExecuteNonQuery(); or start Method AddAuditMasterRecord with
cmdMaster = new OleDbCommand(insertAuditDetailSQL, sqlCon); ??
2)I am useing IDisposible inteface to close connection on destcruction
Do I need to cleanup OleDBCommand ???
3)Anything else i should consider ???
Thanks
public MyClass : IDisposable
{
OleDbCommand cmdDetail ;
public MyClass()
{
sConn = "Correct Connection String";
sqlCon = new OleDbConnection(sConn);
sqlCon.Open();
cmdMaster = new OleDbCommand(insertAuditDetailSQL, sqlCon);
}
public void Dispose()
{
// CLEAN UP HERE!!!
CloseCommand();
}
private void CloseCommand()
{
sqlCon.Close();
}
public void AddAuditMasterRecord(int facilitykey, Guid visitid, int
audittypekey, string tablename, DateTime modifieddate)
{
//Parameters must be in order as in string insertAuditMasterSQL
cmdMaster.Parameters.Add("@Field1", OleDbType.Integer).Value =
facilitykey;
cmdMaster.Parameters.Add("@Field2", OleDbType.Guid).Value =
visitid;
OleDbType.Integer).Value = audittypekey;
cmdMaster.Parameters.Add("@Field3, OleDbType.VarChar).Value =
tablename;
cmdMaster.Parameters.Add("@Field4", OleDbType.DBTimeStamp).Value
= modifieddate;
cmdMaster.ExecuteNonQuery();
cmdMaster.Parameters.Clear();
}
}
I have the code working - just want to make sure it is being coded correctly
I need to run thru a loop to insert multiple records thru Method
AddAuditMasterRecord
I have the OleDBCommand setup and was wondering if I am initializing it
correctly and doing cleanup to optimize performance
1)Should I run cmdMaster.Parameters.Clear(); after each call to
cmdMaster.ExecuteNonQuery(); or start Method AddAuditMasterRecord with
cmdMaster = new OleDbCommand(insertAuditDetailSQL, sqlCon); ??
2)I am useing IDisposible inteface to close connection on destcruction
Do I need to cleanup OleDBCommand ???
3)Anything else i should consider ???
Thanks
public MyClass : IDisposable
{
OleDbCommand cmdDetail ;
public MyClass()
{
sConn = "Correct Connection String";
sqlCon = new OleDbConnection(sConn);
sqlCon.Open();
cmdMaster = new OleDbCommand(insertAuditDetailSQL, sqlCon);
}
public void Dispose()
{
// CLEAN UP HERE!!!
CloseCommand();
}
private void CloseCommand()
{
sqlCon.Close();
}
public void AddAuditMasterRecord(int facilitykey, Guid visitid, int
audittypekey, string tablename, DateTime modifieddate)
{
//Parameters must be in order as in string insertAuditMasterSQL
cmdMaster.Parameters.Add("@Field1", OleDbType.Integer).Value =
facilitykey;
cmdMaster.Parameters.Add("@Field2", OleDbType.Guid).Value =
visitid;
OleDbType.Integer).Value = audittypekey;
cmdMaster.Parameters.Add("@Field3, OleDbType.VarChar).Value =
tablename;
cmdMaster.Parameters.Add("@Field4", OleDbType.DBTimeStamp).Value
= modifieddate;
cmdMaster.ExecuteNonQuery();
cmdMaster.Parameters.Clear();
}
}