我必须使用asp.net和c#将包含4000条记录的excel文件上传到oracle数据库 . 但是它只上传了一部分记录并给出错误“超出最大打开游标数” . 我可以解决这个错误吗?
``public void Button1_Click(object sender,EventArgs e){String savePath = @“C:\ Documents and Settings \ Administrator \ My Documents \ Visual Studio 2005 \ WebSites \ ABC \ Uploads \”;
if (FileUpload1.HasFile)
{
String fileName = FileUpload1.FileName;
savePath += "NewMaster.xls";
FileUpload1.SaveAs(savePath);
Label1.Text = "Your file was saved successfully" ;
Excel.ApplicationClass app = new ApplicationClass();
Excel.Workbook workBook = app.Workbooks.Open(savePath, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
Excel.Worksheet workSheet = (Excel.Worksheet)workBook.ActiveSheet;
int index = 1;
object rowIndex = 1;
object colIndex1 = 1;
object colIndex2 = 2;
object colIndex3 = 3;
object colIndex4 = 4;
object colIndex5 = 5;
object colIndex6 = 6;
object colIndex7 = 7;
object colIndex8 = 8;
object colIndex9 = 9;
object colIndex10 =10;
object colIndex11 = 11;
object colIndex12 = 12;
object colIndex13 = 13;
object colIndex14 = 14;
object colIndex15 = 15;
object colIndex16 = 16;
object colIndex17 = 17;
UYear = DateTime.Today.Year.ToString();
UMonth = DateTime.Today.Month.ToString();
UDay = DateTime.Today.Day.ToString();
UTime=DateTime.Now.ToLongTimeString();
UMonth = FormatDate(UMonth);
UDay = FormatDate(UDay);
UDate = UYear + UMonth + UDay;
try
{
while (((Excel.Range)workSheet.Cells[rowIndex, colIndex1]).Value2 != null)
{
string Ref_no = Removespaces(drop_null(Convert.ToString(((Excel.Range)workSheet.Cells[rowIndex, colIndex1]).Value2)));
string Title =Removespaces( PrepareApostrophe(drop_null(Convert.ToString(((Excel.Range)workSheet.Cells[rowIndex, colIndex2]).Value2))));
string CustomerName = PrepareApostrophe(drop_null(Convert.ToString(((Excel.Range)workSheet.Cells[rowIndex, colIndex3]).Value2)));
string NIC = RemoveFirstSpaces(Removespaces(drop_null(Convert.ToString(((Excel.Range)workSheet.Cells[rowIndex, colIndex4]).Value2))));
string Year =Removespaces( drop_null (Convert.ToString (((Excel.Range)workSheet.Cells[rowIndex, colIndex5]).Value2)));
string YaerDot =drop_null(Convert.ToString ( ((Excel.Range)workSheet.Cells[rowIndex, colIndex6]).Value2));
string Month = Removespaces(drop_null(Convert.ToString(((Excel.Range)workSheet.Cells[rowIndex, colIndex7]).Value2)));
string MonthDot = drop_null (Convert.ToString (((Excel.Range)workSheet.Cells[rowIndex, colIndex8]).Value2));
string Date = Removespaces(drop_null (Convert.ToString(((Excel.Range)workSheet.Cells[rowIndex, colIndex9]).Value2)));
string Address1 = PrepareApostrophe(drop_null(Convert.ToString(((Excel.Range)workSheet.Cells[rowIndex, colIndex10]).Value2)));
string Address2 = PrepareApostrophe(drop_null(Convert.ToString(((Excel.Range)workSheet.Cells[rowIndex, colIndex11]).Value2)));
string Address3 = PrepareApostrophe(drop_null(Convert.ToString(((Excel.Range)workSheet.Cells[rowIndex, colIndex12]).Value2)));
string status = Removespaces(PrepareApostrophe(drop_null(Convert.ToString(((Excel.Range)workSheet.Cells[rowIndex, colIndex13]).Value2))));
string mobileeNo = Removespaces(drop_null(Convert.ToString(((Excel.Range)workSheet.Cells[rowIndex, colIndex14]).Value2)));
string telephoneNo = Removespaces(drop_null(Convert.ToString(((Excel.Range)workSheet.Cells[rowIndex, colIndex15]).Value2)));
string commencement_date = Removespaces(drop_null(Convert.ToString(((Excel.Range)workSheet.Cells[rowIndex, colIndex16]).Value2)));
string insertOriginal = "insert into abc.def(REF_NO,TITLE,CUS_NAME,NIC,YEAR1,MONTH1,DATE1,ADDRESS1,ADDRESS2,ADDRESS3,CIVIL_STATUS,MOBILE_NO,TELE_NO,COMMENCEMENT_DATE,UDATE,UTIME)" +
" values('"+Ref_no +"','"+Title+ "', '"+ CustomerName + "','" + NIC + "','"+Year+"','"+Month +"','"+Date+"','"+Address1+"','"+Address2 +"','"+Address3 +"','"+status +"','"+mobileeNo +"','"+telephoneNo +"','"+commencement_date +"','"+UDate +"','"+UTime +"')";
dm.insertRecords(insertOriginal);
catch(Exception ex)
}
else
{
Label1.Text = "You did not specify a file to upload.";
}
}