我正在使用ReportViewer开发一些报告,在某些时候我必须连接到Oracle数据库以检索一些数据并将其存储在DataTable中。
当DataAdapter执行Fill方法时,我收到此错误:
“尝试读取或写入受保护的内存。这通常表示其他内存已损坏。”
这是代码(不幸的是我无法将sql代码放在过程或其他内容中):
OleDbConnection objConn = new OleDbConnection(ConfigurationManager.ConnectionStrings["Premio"].ConnectionString);
OleDbCommand objCmd = new OleDbCommand();
DataTable objDt = new DataTable();
int vTipoTerr = LoadTipoTerritorio(ReportParameter.ReportData.Parameters.Item("pTerritorio").Value.ToString());
string vDataParametroDataFinal = ReportParameter.ReportData.Parameters.Item("pMesAnoCompetencia").Value.ToString();
int vDataInicial = int.Parse(vDataParametroDataFinal.Substring(0, 4));
vDataInicial = vDataInicial - 1;
vDataInicial = int.Parse(vDataInicial.ToString() + vDataParametroDataFinal.Substring(4, 2));
objCmd.CommandText = "SELECT T.Nome, " +
" T.Prontuario, " +
" C.Cobertura, " +
" Cn.Mesano_competencia, " +
" G.Grupo, " +
" T.Territorio, " +
" N.Negocio " +
" FROM Calculo C " +
" Inner Join Territorio T " +
" ON C.Id_Territorio = T.Id_Territorio " +
" Inner Join Grupo G " +
" ON C.Id_Grupo = G.Id_Grupo " +
" Inner Join Cenario Cn " +
" On Cn.Id_cenario = C.Id_cenario " +
" Inner Join Negocio N " +
" On Cn.Id_negocio = N.Id_negocio " +
" Where Cn.Mesano_competencia Between :p1 And :p2 --datas " +
" And G.Grupo = :p3 " +
" And Sub_terr(T.Territorio, Decode(:p4, 1, 'SETOR', 2, 'DISTRITO', 3, 'REGIONAL')) = :p5 " +
" And (Cn.Flag_cenario_disp = 1 Or Cn.Flag_cenario_disp_rec = 1) " +
" And N.Negocio = :p6 " +
" And Cn.Flag_recuperacao = 0 " +
" Order By Cn.Mesano_competencia; " +
"union all " +
"SELECT T.Nome, " +
" T.Prontuario, " +
" C.Cobertura, " +
" Cn.Mesano_competencia, " +
" G.Grupo, " +
" T.Territorio, " +
" N.Negocio " +
" FROM Calculo_Rec C " +
" Inner Join Territorio T " +
" ON C.Id_Territorio = T.Id_Territorio " +
" Inner Join Grupo G " +
" ON C.Id_Grupo = G.Id_Grupo " +
" Inner Join Cenario Cn " +
" On Cn.Id_cenario = C.Id_cenario " +
" Inner Join Negocio N " +
" On Cn.Id_negocio = N.Id_negocio " +
" Where Cn.Mesano_competencia Between :p1 And :p2 " +
" And G.Grupo = :p3 " +
" And Sub_terr(T.Territorio, Decode(:p4, 1, 'SETOR', 2, 'DISTRITO', 3, 'REGIONAL')) = :p5 " +
" And (Cn.Flag_cenario_disp = 1 Or Cn.Flag_cenario_disp_rec = 1) " +
" And N.Negocio = :p6 " +
" And Cn.Flag_recuperacao = 1 " +
" Order By Cn.Mesano_competencia ";
objCmd.Parameters.Add(new OleDbParameter("p1", OleDbType.Integer)).Value = vDataInicial;
objCmd.Parameters.Add(new OleDbParameter("p2", OleDbType.Integer)).Value = int.Parse(vDataParametroDataFinal);
objCmd.Parameters.Add(new OleDbParameter("p3", OleDbType.VarChar, 30)).Value = ReportParameter.ReportData.Parameters.Item("pGrupo").Value.ToString();
objCmd.Parameters.Add(new OleDbParameter("p4", OleDbType.Integer)).Value = vTipoTerr;
objCmd.Parameters.Add(new OleDbParameter("p5", OleDbType.VarChar, 30)).Value = ReportParameter.ReportData.Parameters.Item("pTerritorio").Value.ToString();
objCmd.Parameters.Add(new OleDbParameter("p6", OleDbType.VarChar, 30)).Value = ReportParameter.ReportData.Parameters.Item("pNegocio").Value.ToString();
OleDbDataAdapter objAdapter = new OleDbDataAdapter(objCmd);
objConn.Open();
objAdapter.Fill(objDt);
objConn.Close();
非常感谢(:
答案 0 :(得分:0)
请尝试使用OracleCommand
和OracleConnection
对象:
OracleConnection objConn = new OracleConnection (ConfigurationManager.ConnectionStrings["Premio"].ConnectionString);
OracleCommand objCmd = new OracleCommand ();