OracleConnection dbConn = new OracleConnection(CONN_STRING);
dbConn.Open();
OracleCommand cmd = new OracleCommand("InsertBulkEmployeeRecord",dbConn);
cmd.CommandType = CommandType.StoredProcedure;
int[] arrEmployeeId={0};
string[] arrName= {""};
string[] arrDesig= {""};
/*Grab EmployeeID(from textbox), EmployeeName(from textbox) and Designation (from dropdownlist)
from webpage controls present in DataGrid in a loop that iterates as many times as the count of
rows in the DataGrid and store them in the 3 arrays*/
// Setting the ArrayCount for command to the number of rows in Grid
cmd.ArrayBindCount = DataGrid.RowCount;
OracleParameter aEmpIDParam = new OracleParameter("Employee ID", OracleDbType.Integer);
aEmpIDParam.Direction = ParameterDirection.Input;
aEmpIDParam.Value = arrEmployeeId;
cmd.Parameters.Add(aEmpIDParam);
/*Similarly for arrName and arrDesig*/
try
{
cmd.ExecuteNonQuery();
LabelStatus.Text = "There was a total of " + cmd.ArrayBindCount + " Employees added.";
LabelStatus.Visible = true;
}
catch (Exception ex)
{
LabelStatus.Text = ex.Message.ToString();
LabelStatus.Visible = true;
}
finally
{
dbConn.Dispose();
}
PROCEDURE InsertBulkEmployeeRecord(pEmpId NUMBER, pName varchar2, pDesignation VARCHAR2)
IS
BEGIN
INSERT INTO EMPLOYEE (EMPLOYEE_ID , NAME, DESIGNATION)
VALUES (pEmpId, pName, pDesignation);
COMMIT;
EXCEPTION WHEN OTHERS THEN
INSERT INTO GTT_INSERTFAILED_EMPID (EMPLOYEE_ID) VALUES (pEmpId);
COMMIT;
END InsertBulkEmployeeRecord;
OracleParameter aNameParam = new OracleParameter("Name", OracleDbType.Varchar2);
aNameParam.Direction = ParameterDirection.Input;
aNameParam.Value = arrName;
cmd.Parameters.Add(aNameParam);
OracleParameter aDesigParam = new OracleParameter("Designation", OracleDbType.Varchar2);
aDesigParam.Direction = ParameterDirection.Input;
aDesigParam.Value = arrDesig;
cmd.Parameters.Add(aDesigParam);