SQL Server 대신 Oracle에서 작동하도록 C# 코드 숨김 중 일부를 변환하는 임무가 있습니다. 오라클에 대한 제 경험은 ... 오 ... 2 일입니다.Oracle에서 DataReader를 올바르게 사용하고 있습니까?
그래서, 여기에 내가 가진 무엇 :
private void LoadPreferences()
{ // inital load of users function and role based on last action performed in database
try
{
OracleConnection oConn = GetConnection();
//string selectSQL = "select Function_ID,Role_ID from vw_mos_DPL_Last_Selection where Lan_ID = '" + strUserID + "'";
//string selectSQL = "select Function_ID,Role_ID from vw_mos_DPL_Last_Selection where Lan_ID = @strUserID";
//string selectSQL = "SELECT WORK_ID, ROLE_ID, ACTIVITY_ID, LAN_ID, CREATE_TS FROM THN_DPL_DETAIL WHERE Lan_ID = @strUserID ORDER BY CREATE_TS DESC";
string selectSQL = "SELECT * FROM(";
selectSQL = selectSQL + "SELECT TB.BUS_ID, TL.LOB_ID, TD.ROLE_ID, TL.LOB_ID, TD.ACTIVITY_ID, TD.LAN_ID, TD.CREATE_TS ";
selectSQL = selectSQL + "FROM THN_DPL_DETAIL TD ";
selectSQL = selectSQL + "LEFT JOIN THN_ACTIVITY TA ON TD.Activity_ID = TA.Activity_ID ";
selectSQL = selectSQL + "LEFT JOIN THN_ROLE TR ON TR.ROLE_ID = TA.Role_ID ";
selectSQL = selectSQL + "LEFT JOIN THN_LOB TL On TL.LOB_ID = TA.LOB_ID ";
selectSQL = selectSQL + "LEFT JOIN THN_BUSINESS TB ON TB.BUS_ID = TR.BUS_ID ";
selectSQL = selectSQL + "WHERE Lan_ID = @strUserID ";
selectSQL = selectSQL + "ORDER BY CREATE_TS DESC";
selectSQL = selectSQL + ") WHERE ROWNUM = 1;";
OracleCommand cmd = new OracleCommand(@selectSQL, oConn);
cmd.Parameters.AddWithValue("@strUserID", strUserID);
OracleDataReader reader;
oConn.Open();
reader = cmd.ExecuteReader();
//read first line
reader.Read();
if (reader.HasRows == true)
{
//First, grab the bytes from the reader: AA = Bus_ID, BB = LOB_ID and CC = Role_ID
byte AA = reader.GetByte(0);
byte BB = reader.GetByte(1);
byte CC = reader.GetByte(2);
//Now set the SelectedValue of Business and re-query the LOB dropdown for eligible values
CallBus_DrpDwnLst.SelectedValue = AA.ToString();
LOBLoad();
//Now set the SelectedValue of LOB since it's filled with eligible valuse
CallLOB_DrpDwnLst.SelectedValue = BB.ToString();
CallRoleLoad();
//Now set the SelectedValue of Role since it's filled with eligible valuse
CallRole_DrpDwnLst.SelectedValue = CC.ToString();
}
else //no rows found, clear selection
{
CallBus_DrpDwnLst.SelectedIndex = 0;
CallLOB_DrpDwnLst.SelectedIndex = 0;
CallRole_DrpDwnLst.SelectedIndex = 0;
}
//close the reader
reader.Close();
oConn.Close();
}
catch (Exception ex)
{
// Handle the error
Response.Write(ex.Message);
//ErrorLogging.WriteToEventLog(ex);
}
}
제가하는 데 문제는 라인에 reader = cmd.ExecuteReader()
내가 오류 받고 있어요 점이다
ORA-01036: illegal variable name/number
이 사람이 나를 도울 수를 이? strUserID가 코드를 단계별로 검사하기 때문에 제대로 분석된다는 것을 알고 있습니다. 대신 선택하고 당신의 쿼리에
'@ strUserID' 나는 생각한다; 그걸': strUserID'로 변경하고 addWithValue를'strUserID'로 변경하면 더 행복할까요? –
이제는 "SQL 명령이 제대로 종료되지 않았습니다"라는 메시지가 나타납니다. –
명령 끝에서 세미콜론을 사용하지 않으려는 경우 ORA-00911이 표시됩니다. 당신의 운전 기사가 그것을 잡지 않는 한. –