本文介绍了错误错误错误...........的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data;
using Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.Data.Odbc;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Collections;

namespace SearchResources
{
    class parameter
    {
        public bool RetrieveResources()
        {
            OleDbConnection SQLConn = null;
            System.Data.DataTable dt = new System.Data.DataTable(parameter.PRSheetName);

             if (parameter.PRFileName.Trim().EndsWith(".xlsx"))
            {
               strConnectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES\";", objUploadDetailsDataClass.RRFileName);
            }
            else if (objUploadDetailsDataClass.RRFileName.Trim().EndsWith(".xls"))
            {
                strConnectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=Yes\";", objUploadDetailsDataClass.RRFileName);
            }
           SQLConn = new OleDbConnection(strConnectionString);
            SQLConn.Open();
            OleDbDataAdapter SQLAdapter = new OleDbDataAdapter();
             OleDbCommand selectCMD = new OleDbCommand(parameter.PRQuery(), SQLConn);
            selectCMD.Parameters.AddWithValue("@position status updated", "position open");
            selectCMD.Parameters.AddWithValue("@CTP Yes/No", "Yes");
            // selectCMD.Parameters.AddWithValue("@Month", DateTime.Now.Year.ToString());
            SQLAdapter.SelectCommand = selectCMD;
            DataSet objDataset1 = new DataSet();
            SQLAdapter.Fill(objDataset1);
           PRdt = objDataset1.Tables[0];
        }
    }
}


错误-当前上下文中不存在名称"PRSheetName"
错误-"SearchResources.parameter"不包含"PRSheetName"的定义
错误-"SearchResources.parameter"不包含"PRFileName"的定义
错误-当前上下文中不存在名称"strConnectionString"
错误-当前


Error-The name ''PRSheetName'' does not exist in the current context
Error-''SearchResources.parameter'' does not contain a definition for ''PRSheetName''
Error-''SearchResources.parameter'' does not contain a definition for ''PRFileName''
Error-The name ''strConnectionString'' does not exist in the current context
Error-The name ''objUploadDetailsDataClass'' does not exist in the current

推荐答案

private string PRSheetName;

在您的类中,尝试使用该方法时,将立即获得未设置为实例的对象"异常!

顺便说一句:不要将您的类称为参数":约定是,类以大写字母开头.尝试使用参数",它更加一致.

in your class, you will get a "object not set to an instance" exception as soon as you try to use the method!

BTW: Don''t call your class "parameter": the convention is that classes start with an Upper case letter. Try "Parameter" instead, it is more consistant.


namespace SearchResources
{
    //Start the name of a class with a capital letter
    class Parameter
    {
        //add arguments to your method
        //you may need to change your return type depending on what you really want to do
        public DataTable RetrieveResources(string PRSheetName, string PRFileName)
        {
            //declare a the variables you will use later
            string strConnectionString = "";
            //declate the objUploadDetailsDataClass here or pass it as an argument
            //or as a property of your class: I don't know what should be the type,
            //but you probably do...
            object objUploadDetailsDataClass = ...;
            OleDbConnection SQLConn = null;
            //use the arguments
            System.Data.DataTable dt = new System.Data.DataTable(PRSheetName);
             if (PRFileName.Trim().EndsWith(".xlsx"))
            {
               strConnectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=\"Excel 12.0 Xml;HDR=YES\";", objUploadDetailsDataClass.RRFileName);
            }
            else if (objUploadDetailsDataClass.RRFileName.Trim().EndsWith(".xls"))
            {
                strConnectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR=Yes\";", objUploadDetailsDataClass.RRFileName);
            }
           SQLConn = new OleDbConnection(strConnectionString);
            SQLConn.Open();
            OleDbDataAdapter SQLAdapter = new OleDbDataAdapter();
            //remove "parameter"
             OleDbCommand selectCMD = new OleDbCommand(PRQuery(), SQLConn);
            selectCMD.Parameters.AddWithValue("@position status updated", "position open");
            selectCMD.Parameters.AddWithValue("@CTP Yes/No", "Yes");
            // selectCMD.Parameters.AddWithValue("@Month", DateTime.Now.Year.ToString());
            SQLAdapter.SelectCommand = selectCMD;
            DataSet objDataset1 = new DataSet();
            SQLAdapter.Fill(objDataset1);
           //you should declare the PRDt variable somewhere
           //and you should do something with it: maybe you want to return it?
           return objDataset1.Tables[0];
        }

        //add this method
        string PRQuery()
        {
             //do something...
        }
    }
}


这篇关于错误错误错误...........的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 22:17