简体   繁体   中英

ORA-01036: ILLEGAL VARIABLE NAME/NUMBER while filling the data table

I have a view in oracle DB and i am trying to call it from a method to to bind the data coming from the view to a data table but it raises the exception.

Please help.

Exception is raised in this line ( dataAdapter.Fill(dataTable);)

 private static void ViewSelectedJobHistory(Document imDocument, Job selectedJob)
            {
                DataTable dataTable = new DataTable();
                try
                {
                    if (imDocument != null && selectedJob != null)
                    {
                        //string query =JobResource.QueryJobHistory;
                        //int id=selectedJob.ID;                
                        //using (Command imCommand = new Command(query, imDocument.Connection))
                        string query = string.Format("select FID,F_CLASS_NAME,JOB_OPERATION_TYPE,OPERATION_DATE from JOB_EXPLORER_FETCH where JOB_ID={0}",selectedJob.ID);
                            //"select FID,F_CLASS_NAME,JOB_OPERATION_TYPE,OPERATION_DATE from JOB_EXPLORER_FETCH where JOB_ID=34680";
                        string abc = query;
                        using (Command imCommand = new Command(query, imDocument.Connection))
                        {
                            imCommand.Parameters.Add(new DataParameter("1", DbDataType.String, selectedJob.ID.ToString(), ParameterDirection.Input));

                            using (DataAdapter dataAdapter = new DataAdapter(imCommand))
                            {
                                dataAdapter.Fill(dataTable);
                                if (dataTable != null && dataTable.Rows.Count > 0 )
                                {
                                    if (instanceJob == false)
                                    {
                                        ViewSelectedJobHistory viewSelectedJobHistory = new ViewSelectedJobHistory(imDocument, dataTable, selectedJob);
                                        viewSelectedJobHistory.Show();
                                        instanceJob = true;
                                    }
                                }

遇到 dataadapter.fill 方法时的异常消息

You are attempting to bind the parameters twice, and also are not using the Oracle libraries (guessing because I don't see your connection open code).

The SQL command should look like this:

string query = "select FID,F_CLASS_NAME,JOB_OPERATION_TYPE,OPERATION_DATE from JOB_EXPLORER_FETCH where JOB_ID=:0";

Then when youre adding the parameter, it should replace the :0 with your value. This is also essential to avoid SQL Injection attacks. Additionally you should be using an OracleParameter class:

imCommand.Parameters.Add(new OracleParameter("1", OracleDbType.NVarchar2, 100, selectedJob.ID.ToString(), ParameterDirection.Input));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM