我写了3个类文件,用于调用,代码如下:
CLASS 1:
public ArrayList GetData(ArrayList StrStructList)
{
for (int num1 = 0; num1 < StrStructList.Count; num1++)
{
StrStruct struct1 = (StrStruct) StrStructList[num1];
OleDbCommand command1 = new OleDbCommand(struct1.m_SqlStr, this.Mycon);
if (struct1.m_Type == DataAccessType.ReturnValue)
{
command1.Connection = this.Mycon;
command1.CommandText = struct1.m_SqlStr;
if (this.m_IsCommitTran)
{
command1.Transaction = this.Mytran;
}
struct1.m_ReturnObj = command1.ExecuteScalar().ToString();
}
}
if (this.m_IsCommitTran)
{
this.Mytran.Commit();
}
if (this.m_IsAutoClosed)
{
this.CloseCon();
}
return StrStructList;
}
CLASS 2:
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;namespace BussinessOffice.ClassPub
{
public class StrStruct
{
public object m_ReturnObj;
public string m_SqlStr;
public string m_TableName;
public DataAccessType m_Type; public StrStruct(string SlqStr, string TableName, DataAccessType ReturnType, object ReturnObj)
{
this.m_SqlStr = SlqStr;
this.m_TableName = TableName;
this.m_Type = ReturnType;
this.m_ReturnObj = ReturnObj;
}
}
}
CLASS 3:
using System;
namespace BussinessOffice.ClassPub
{
/// <summary>
/// DataAccessType 的摘要说明。
/// </summary>
public class DataAccessType
{ public DataAccessType()
{
}
enum DataAccessType1
{
// Fields
ReturnDataReader = 1,
ReturnDataSet = 0,
ReturnEmpty = 3,
ReturnValue = 2
};
}
}
但是第一个类(class1)编译报错:
E:\wf\www\BussinessOffice\ClassPub\ClassPub.OLEDBonline\OperationClass.cs(164): 运算符“==”无法应用于“BussinessOffice.ClassPub.DataAccessType”和“int”类型的操作数
好象是我的class3类有问题。请高手指点。

解决方案 »

  1.   

    z这里
    if (struct1.m_Type == DataAccessType.ReturnValue)运算符“==”无法应用于“BussinessOffice.ClassPub.DataAccessType”和“int”类型的操作数
      

  2.   

    xiahouwen(活靶子.NET) :
    你好。我也晓得是这里的问题。但是我现在不清楚该怎么改啊。帮忙啦
      

  3.   

    if (struct1.m_Type == DataAccessType.ReturnValue)改成用Switch分枝语句判断DataAccessType1 dataAccessType;
    switch(dataAccessType)
    {
    case DataAccessType1.ReturnValue:
    ....
    break;
    case DataAccessType1.ReturnDataReader:
    ...
    break;
    .....
    }
      

  4.   

    CLASS 1:
    public ArrayList GetData(ArrayList StrStructList)
    {
    for (int num1 = 0; num1 < StrStructList.Count; num1++)
    {
    StrStruct struct1 = (StrStruct) StrStructList[num1];
    OleDbCommand command1 = new OleDbCommand(struct1.m_SqlStr, this.Mycon);
    if (struct1.m_Type == DataAccessType.DataAccessType.DataAccessType1.ReturnValue)
    {
    command1.Connection = this.Mycon;
    command1.CommandText = struct1.m_SqlStr;
    if (this.m_IsCommitTran)
    {
    command1.Transaction = this.Mytran;
    }
    struct1.m_ReturnObj = command1.ExecuteScalar().ToString();
    }
    }
    if (this.m_IsCommitTran)
    {
    this.Mytran.Commit();
    }
    if (this.m_IsAutoClosed)
    {
    this.CloseCon();
    }
    return StrStructList;
    }
    CLASS 2:
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;namespace BussinessOffice.ClassPub
    {
    public class StrStruct
    {
    public object m_ReturnObj;
    public string m_SqlStr;
    public string m_TableName;
    public DataAccessType.DataAccessType.DataAccessType1 m_Type; public StrStruct(string SlqStr, string TableName, DataAccessType ReturnType, object ReturnObj)
    {
    this.m_SqlStr = SlqStr;
    this.m_TableName = TableName;
    this.m_Type = ReturnType;
    this.m_ReturnObj = ReturnObj;
    }
    }
    }
    CLASS 3:
    using System;
    namespace BussinessOffice.ClassPub
    {
    /// <summary>
    /// DataAccessType 的摘要说明。
    /// </summary>
    public class DataAccessType
    { public DataAccessType()
    {
    }
    public enum DataAccessType1
    {
    // Fields
    ReturnDataReader = 1,
    ReturnDataSet = 0,
    ReturnEmpty = 3,
    ReturnValue = 2
    };
    }
    }
      

  5.   

    CLASS 1:
    public ArrayList GetData(ArrayList StrStructList)
    {
    for (int num1 = 0; num1 < StrStructList.Count; num1++)
    {
    StrStruct struct1 = (StrStruct) StrStructList[num1];
    OleDbCommand command1 = new OleDbCommand(struct1.m_SqlStr, this.Mycon);
    if (struct1.m_Type == BussinessOffice.ClassPub.DataAccessType.DataAccessType1.ReturnValue)
    {
    command1.Connection = this.Mycon;
    command1.CommandText = struct1.m_SqlStr;
    if (this.m_IsCommitTran)
    {
    command1.Transaction = this.Mytran;
    }
    struct1.m_ReturnObj = command1.ExecuteScalar().ToString();
    }
    }
    if (this.m_IsCommitTran)
    {
    this.Mytran.Commit();
    }
    if (this.m_IsAutoClosed)
    {
    this.CloseCon();
    }
    return StrStructList;
    }
    CLASS 2:
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;namespace BussinessOffice.ClassPub
    {
    public class StrStruct
    {
    public object m_ReturnObj;
    public string m_SqlStr;
    public string m_TableName;
    public BussinessOffice.ClassPub.DataAccessType.DataAccessType1 m_Type; public StrStruct(string SlqStr, string TableName, DataAccessType ReturnType, object ReturnObj)
    {
    this.m_SqlStr = SlqStr;
    this.m_TableName = TableName;
    this.m_Type = ReturnType;
    this.m_ReturnObj = ReturnObj;
    }
    }
    }
    CLASS 3:
    using System;
    namespace BussinessOffice.ClassPub
    {
    /// <summary>
    /// DataAccessType 的摘要说明。
    /// </summary>
    public class DataAccessType
    { public DataAccessType()
    {
    }
    public enum DataAccessType1
    {
    // Fields
    ReturnDataReader = 1,
    ReturnDataSet = 0,
    ReturnEmpty = 3,
    ReturnValue = 2
    };
    }
    }