getting " Object type cannot be converted to target type." with dataAdapter using storedProc

D

Dica

i'm getting an error when trying set my dataAdapter's selectCommand. the
sqlStatement is a storedProc which takes parameters, so it's constructed as:

sqlSelectCommand1.CommandText = "[uspProjectListUser]";

sqlSelectCommand1.CommandType = System.Data.CommandType.StoredProcedure;

sqlSelectCommand1.Connection = sqlConnection1;

sqlSelectCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
false, ((System.Byte)(0)), ((System.Byte)(0)), "",
System.Data.DataRowVersion.Current, null));

sqlSelectCommand1.Parameters.Add("@iCompanyID", SqlDbType.Int).Value = 1;

sqlSelectCommand1.Parameters.Add("@iUserID", SqlDbType.Int).Value = 4;



when i pass this to my dataAdapter as:

oDataAdapter.SelectCommand = sqlSelectCommand1;

i get an error:

" Object type cannot be converted to target type."

i've tried commenting out the parameters, and then have no problems setting
the dataAdapter's selectCommand.



how can i fix this?

tks
 
T

Tomas Vera

What's the "signature" of your stored procedure?
Are the params correct for the proc?
Also, how are you passing back the return value?

-tomas

i'm getting an error when trying set my dataAdapter's selectCommand. the
sqlStatement is a storedProc which takes parameters, so it's constructed as:

sqlSelectCommand1.CommandText = "[uspProjectListUser]";

sqlSelectCommand1.CommandType = System.Data.CommandType.StoredProcedure;

sqlSelectCommand1.Connection = sqlConnection1;

sqlSelectCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue,
false, ((System.Byte)(0)), ((System.Byte)(0)), "",
System.Data.DataRowVersion.Current, null));

sqlSelectCommand1.Parameters.Add("@iCompanyID", SqlDbType.Int).Value = 1;

sqlSelectCommand1.Parameters.Add("@iUserID", SqlDbType.Int).Value = 4;



when i pass this to my dataAdapter as:

oDataAdapter.SelectCommand = sqlSelectCommand1;

i get an error:

" Object type cannot be converted to target type."

i've tried commenting out the parameters, and then have no problems setting
the dataAdapter's selectCommand.



how can i fix this?

tks

/*-------------------------------
* Tomas Vera
* tomas (at) sbcglobal (dot) net
*-------------------------------
*/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top