为命令对象错误定义了Sql Parameters和No命令文本

时间:2013-05-05 11:50:32

标签: c# .net sql oledb sqlparameters

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

这是我的代码:

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       \"

任何人都有一些想法?

非常感谢,

致以最诚挚的问候,

Nixeus

1 个答案:

答案 0 :(得分:1)

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

您已经拥有一个命令,无需创建新命令。