请那位.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);
}
}
}
把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),所以不能访问。
谢谢您的指教,按照您说的,我已经改正了。还有以下黑体字的地方如何修改,请您指教,本人实在无法修改,只是在学习:
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;
}
把get_和set_去掉就行
记住方法名前面永远不要加get,set
这个是反编译出来的??
是反编译出来的,不知正确的语句如何写,请麻烦帮助一下,多谢
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));