0

我想用 c# 创建我的第一个 SQL 参数命令,但我有一个错误:“没有为命令对象定义命令文本”

这是我的代码:

string maRequete = "UPDATE "  + strNomTable + " set everelance = @everelance,"
    + "evedate = @evedate ,"
    + "evedatemo = @evedatemo ,"
    + "evetype = @evetype ,"
    + "evedes = @evedes ,"
    + "evecli = @evecli ,"
    + "evestatut = @evestatut ,"
    + "eveusermo = @eveusermo ,"
    + "eveinterv = @eveinterv where eveNum = " + '"' + strEvtNumeroString.ToString() + '"';

OleDbCommand DbCommand = new OleDbCommand(maRequete);

DbCommand.Parameters.Add("@everelance", OleDbType.Date);
DbCommand.Parameters.Add("@evedate", OleDbType.Date);
DbCommand.Parameters.Add("@evedatemo", OleDbType.Date);
DbCommand.Parameters.Add("@evetype", OleDbType.VarChar);
DbCommand.Parameters.Add("@evedes", OleDbType.VarChar);
DbCommand.Parameters.Add("@evecli", OleDbType.VarChar);
DbCommand.Parameters.Add("@evestatut", OleDbType.VarChar);
DbCommand.Parameters.Add("@eveusermo", OleDbType.VarChar);
DbCommand.Parameters.Add("@eveinterv", OleDbType.VarChar);

DbCommand.Parameters["@everelance"].Value = m_dDateRelance.Date.ToString("d", m_UsCulture);
DbCommand.Parameters["@evedate"].Value = m_dDate.ToString(m_UsCulture);
DbCommand.Parameters["@evedatemo"].Value = m_dDateModificaton.ToString(m_UsCulture);
DbCommand.Parameters["@evetype"].Value = m_strEvtType.ToString().Trim();
DbCommand.Parameters["@evedes"].Value = m_strDesignation.ToString().Trim();
DbCommand.Parameters["@evecli"].Value = m_strCodeClient.ToString().Trim();
DbCommand.Parameters["@evestatut"].Value = "";
DbCommand.Parameters["@eveusermo"].Value = m_strUserModification;
DbCommand.Parameters["@eveinterv"].Value = m_strCodeIntervenant.ToString().Trim();

try
{
    string strStringConnect = @"Provider=vfpoledb.1;Data Source=" + m_strDirectoryDBF + @"\" + strDbfFile + ".dbf;Collating Sequence=general";
    OleDbConnection DbConnection = new OleDbConnection(strStringConnect);


    DbConnection.Open();
    DbCommand.Connection = DbConnection;


    DbCommand = DbConnection.CreateCommand();

    DbCommand.ExecuteNonQuery();
    return "O";
}
catch (Exception Ex)
{
    return Ex.Message;
}

ExecuteNonQuery 引发异常:“没有为命令对象定义命令文本”错误。

这是我的请求:(在调试模式下):

    UPDATE ZZAg7eve set everelance = @everelance,
evedate = @evedate ,
evedatemo = @evedatemo ,
evetype = @evetype ,
evedes = @evedes ,
evecli = @evecli ,
evestatut = @evestatut ,
eveusermo = @eveusermo ,
eveinterv = @eveinterv where eveNum = \"00000003       \"

有人有什么想法吗?

非常感谢,

此致,

尼克修斯

4

1 回答 1

1

删除这一行:DbCommand = DbConnection.CreateCommand();

你已经有一个命令,不需要创建一个新的。

于 2013-05-05T11:58:53.070 回答