首页 新闻 会员 周边 捐助

请问生成dll时出错

0
悬赏园豆:50 [待解决问题]

请那位.NET编程高手帮我检查以下程序,在生成dll时报错:“System.Data.Common.DbCommand.CommandText.set”: 无法显式调用运算符或访问器。

“System.Data.Common.DbConnection.State.get”: 无法显式调用运算符或访问器。

......类似的错误

正确的写法应该是什么?本人是新手,在读他人写的程序,对您的帮助非常感谢!!

下面黑体部分是出错的地方。

public static int InsertAndReturnID(string connString, string cmdText, params OleDbParameter[] cmdParms)
        {
            int num = 0;
            OleDbCommand cmd = new OleDbCommand();
            using (OleDbConnection connection = new OleDbConnection(connString))
            {
                PrepareCommand(cmd, connection, null, CommandType.Text, cmdText, cmdParms);
                int num2 = cmd.ExecuteNonQuery();
                cmd.Parameters.Clear();
                if (num2 == 1)
                {
                    cmd.set_CommandText("SELECT @@IDENTITY AS ID");
                    num = (int) cmd.ExecuteScalar();
                }
            }
            return num;
        }
private static void PrepareCommand(OleDbCommand cmd, OleDbConnection conn, OleDbTransaction trans, CommandType cmdType, string cmdText, OleDbParameter[] cmdParms)
        {
            if (conn.get_State() != ConnectionState.Open)
            {
                conn.Open();
            }
            cmd.Connection = conn;
            cmd.set_CommandText(cmdText);
            if (trans != null)
            {
                cmd.Transaction = trans;
            }
            cmd.set_CommandType(cmdType);
            if (cmdParms != null)
            {
                foreach (OleDbParameter parameter in cmdParms)
                {
                    cmd.Parameters.Add(parameter);
                }
            }
        }

郝建的主页 郝建 | 初学一级 | 园豆:150
提问于:2011-09-23 14:57
< >
分享
所有回答(4)
1

cmd.set_CommandText("SELECT @@IDENTITY AS ID");改成cmd.CommandText="SELECT @@IDENTITY AS ID";

conn.get_State() != ConnectionState.Open改成conn.State != ConnectionState.Open等等。。。

CommandText,State,CommandType之类的是对象cmd和conn的属性,而get_***和set_***是编译时生成的用来访问这个属性的方法,这些方法不是公开的(public),所以不能访问。

wang_yb | 园豆:4893 (老鸟四级) | 2011-09-23 15:06

谢谢您的指教,按照您说的,我已经改正了。还有以下黑体字的地方如何修改,请您指教,本人实在无法修改,只是在学习:

public static bool UploadPrimalFile(FileUpload fileUpload, ref string primalFileName, ref string errorMessage)
        {
            if (fileUpload.get_HasFile())
            {
                string str = fileUpload.get_FileName();
                if (str.IndexOf(".") != -1)
                {
                    string path = string.Format("~/Picture/{0}-{1}", DateTime.Now.Year, DateTime.Now.Month);
                    if (!Directory.Exists(HttpContext.Current.Server.MapPath(path)))
                    {
                        try
                        {
                            Directory.CreateDirectory(HttpContext.Current.Server.MapPath(path));
                        }
                        catch (Exception exception)
                        {
                            errorMessage = exception.Message;
                            return false;
                        }
                    }
                    primalFileName = string.Format("{0}/primal{1}{2}", path, DateTime.Now.ToString("yyyyMMddhhmmssms"), str.Substring(str.LastIndexOf(".")));
                    if (File.Exists(HttpContext.Current.Server.MapPath(primalFileName)))
                    {
                        errorMessage = "同名图片已存在";
                        primalFileName = string.Empty;
                        return false;
                    }
                    try
                    {
                        fileUpload.get_PostedFile().SaveAs(HttpContext.Current.Server.MapPath(primalFileName));
                    }
                    catch (Exception exception2)
                    {
                        errorMessage = exception2.Message;
                        primalFileName = string.Empty;
                        return false;
                    }
                    return true;
                }
            }
            errorMessage = "没有选择图片";
            return false;
        }

支持(0) 反对(0) 郝建 | 园豆:150 (初学一级) | 2011-09-23 17:40

把get_和set_去掉就行

 

支持(0) 反对(0) wang_yb | 园豆:4893 (老鸟四级) | 2011-10-05 20:55
0

记住方法名前面永远不要加get,set

jewely | 园豆:109 (初学一级) | 2011-09-23 17:02
0

这个是反编译出来的??

OOLi | 园豆:163 (初学一级) | 2011-09-23 22:40

是反编译出来的,不知正确的语句如何写,请麻烦帮助一下,多谢

支持(0) 反对(0) 郝建 | 园豆:150 (初学一级) | 2011-09-26 09:09
0

  if (fileUpload.get_HasFile())
            {
                string str = fileUpload.get_FileName();

}


fileUpload.get_PostedFile().SaveAs(HttpContext.Current.Server.MapPath(primalFileName));
                

----------------------------------

  if (fileUpload.HasFile)
            {
                string str = fileUpload.FileName;

}


fileUpload.PostedFile().SaveAs(HttpContext.Current.Server.MapPath(primalFileName));
                

waninlezu | 园豆:661 (小虾三级) | 2011-09-27 12:01
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册