Note that there are some explanatory texts on larger screens.

plurals
  1. POAdo.net data provider is throwing an error when I try to return a command from a method
    primarykey
    data
    text
    <p>I'm sorry for the bad title, not certain how to describe the issue completely. </p> <p>I'm using SQLBase NET data provider.</p> <p>When I attempt to create a command and add parameters, it is throwing an exception</p> <blockquote> <p><em>Object not set to instance of an object</em> </p> </blockquote> <p>However, when I create a command outside of my object, I can add parameters with no issues.</p> <p><code>SQLBaseDatabase</code> class is a wrapper I wrote that will basically return a connection and create a command.</p> <pre><code>var db = new SQLBaseDatabase(ConfigurationManager.ConnectionStrings["UDSConnectionString"].ConnectionString); </code></pre> <p>This code works: I created this code in my <code>HomeController</code> as a test. I can add parameters with no problem.</p> <pre><code>var command = new SQLBaseCommand(); command.Connection = db.GetConnection() as SQLBaseConnection; command.Parameters.Add(db.GetParameter(":1", "1234", DbType.String)); </code></pre> <p>This code fails:</p> <pre><code>var parameters = new List&lt;IDataParameter&gt;(); parameters.Add(db.GetParameter(":1", "1234", DbType.String)); var cmd = db.GetCommand(db.GetConnection(), "Select * From DX_CODES Where (DX = :1)", parameters); </code></pre> <p>When I try to add parameters in this method via the passed in parameters, it throws the object not set error.</p> <pre><code>public IDbCommand GetCommand(IDbConnection connection, string sql, IEnumerable&lt;IDataParameter&gt; parameters) { var command = new SQLBaseCommand(connection as SQLBaseConnection); foreach (var parameter in parameters) command.Parameters.Add(parameter); // This throws an error. Command.Parameters is read only. command.CommandText = sql; return command; } </code></pre> <p>The command parameters is read only</p> <p>Here is my method that creates the parameter</p> <pre><code> public IDbDataParameter GetParameter(string name, object value, DbType type) { return new SQLBaseParameter(name, type, value); } </code></pre> <p>I'm not sure if I'm fundamentally doing some wrong in c# that could be causing this error. Or how I can fix it considering it works in one case, but not the other.</p> <p>** Update ** Same issue happens with the SqlServer ADO.Provider.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload