Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

type conversion problem 1

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
US
I have some code that I converted from a vb.net site I used to have to c#. But I am getting an error.

Code:
		// Private Code
		//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

		// Private routine allowed only by this base class, it automates the task
		// of building a SqlCommand object designed to obtain a return value from
		// the stored procedure.
		// ---
		private SqlCommand BuildIntCommand(string storedProcName, IDataParameter[] parameters)
		{

			SqlCommand command = BuildQueryCommand(storedProcName, parameters);
			SqlParameter parameter = new SqlParameter();


			parameter.ParameterName = "ReturnValue";
			parameter.DbType = SqlDbType.Int;       <-- Error here
			parameter.Size = 4;
			parameter.Direction = ParameterDirection.ReturnValue;
			parameter.IsNullable = false;
			parameter.Precision = 0;
			parameter.Scale = 0;
			parameter.SourceColumn = string.Empty;
			parameter.SourceVersion = DataRowVersion.Default;
			parameter.Value = null;
			command.Parameters.Add(parameter);


			return command;

		}


		// Builds a SqlCommand designed to return a SqlDataReader,
		// and not an actual integer value.
		// ----
		private SqlCommand BuildQueryCommand(string storedProcName, IDataParameter[] parameters)
		{

			SqlCommand command = new SqlCommand(storedProcName, myConnection);
			command.CommandType = CommandType.StoredProcedure;

			SqlParameter parameter = null;

			if ((parameters != null)) {
				foreach (SqlParameter parameter_loopVariable in parameters) {
					parameter = parameter_loopVariable;
					command.Parameters.Add(parameter);
				}
			}

			return command;

		}


At the line:

parameter.DbType = SqlDbType.Int;

The error is:

Cannot implicitly convert type 'System.Data.SqlDbType'

I don't have the error in VB.Net, why here and what cast would I have to use or do I need to convert it somehow.

Thanks,

Tom
 
the DbType property is a System.data.DbType, not a System.Data.SqlDbType. Try;
Code:
parameter.DbType = DbType.Int32;

Rhys

"Technological progress is like an axe in the hands of a pathological criminal"
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe"
Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top