SqlCommand.DeriveParameters failed

衣舞晨風發表於2015-07-14

錯誤資訊如下:

SqlCommand.DeriveParameters failed because the SqlCommand.CommandText property value is an invalid multipart name "SELECT * from tableA", the current limit of "4" is insufficient。

錯誤原因:

使用Enterprise Library進行資料庫操作時,如果直接使用sql 語句而非儲存過程,一定要用過載方法:
_db.ExecuteDataSet(CommandType type,String sql)

而不是:

public virtual DataSet ExecuteDataSet(
	string storedProcedureName,
	params Object[] parameterValues
)

詳細介紹:點選開啟連結

或者通過sql,獲取到DbCommand,再執行:


ExecuteDataSet過載方法如下:

Database.ExecuteDataSet Method (DbCommand)

public virtual DataSet ExecuteDataSet(
	DbCommand command
)

Database.ExecuteDataSet Method (CommandType, String)

public virtual DataSet ExecuteDataSet(
	CommandType commandType,
	string commandText
)

Database.ExecuteDataSet Method (DbCommand, DbTransaction)

public virtual DataSet ExecuteDataSet(
	DbCommand command,
	DbTransaction transaction
)

Database.ExecuteDataSet Method (String, Object[])

public virtual DataSet ExecuteDataSet(
	string storedProcedureName,
	params Object[] parameterValues
)

Database.ExecuteDataSet Method (DbTransaction, CommandType, String)

public virtual DataSet ExecuteDataSet(
	DbTransaction transaction,
	CommandType commandType,
	string commandText
)

Database.ExecuteDataSet Method (DbTransaction, String, Object[])

public virtual DataSet ExecuteDataSet(
	DbTransaction transaction,
	string storedProcedureName,
	params Object[] parameterValues
)


相關文章