[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.odbcnet

OdbcParameter - Invalid parameter type

Thuy Nguyen

5/2/2002 6:47:00 PM

I'm getting this exception error, "ERROR[HY105][Sybase
[ODBC Driver]Invalid parameter type" after calling
dataReader =
odbcCommand.ExecuteReaderCommandBehavior.SingleRow);

I checked and double checked my CommandParameter list and
they seemed to checkout ok.

This is my code:
OdbcDataReader dataReader;
OdbcCommand odbcCommand = new
OdbcCommand();

odbcCommand.CommandType =
CommandType.Text;
odbcCommand.CommandText = "SELECT
name, nUnit, dob, room, bed, allergies FROM tblPatient
WHERE (id = ?)";
odbcCommand.Parameters.Add(new
OdbcParameter("name", OdbcType.VarChar, 30,
System.Data.ParameterDirection.Output, false,
((System.Byte)(0)), ((System.Byte)(0)), "name",
System.Data.DataRowVersion.Current, null));
odbcCommand.Parameters.Add(new
OdbcParameter("nUnit", OdbcType.VarChar, 10,
System.Data.ParameterDirection.Output, false,
((System.Byte)(0)), ((System.Byte)(0)), "nUnit",
System.Data.DataRowVersion.Current, null));
odbcCommand.Parameters.Add(new
OdbcParameter("dob", OdbcType.VarChar, 10,
System.Data.ParameterDirection.Output, false,
((System.Byte)(0)), ((System.Byte)(0)), "dob",
System.Data.DataRowVersion.Current, null));
odbcCommand.Parameters.Add(new
OdbcParameter("room", OdbcType.VarChar, 10,
System.Data.ParameterDirection.Output, false,
((System.Byte)(0)), ((System.Byte)(0)), "room",
System.Data.DataRowVersion.Current, null));
odbcCommand.Parameters.Add(new
OdbcParameter("bed", OdbcType.VarChar, 2,
System.Data.ParameterDirection.Output, false,
((System.Byte)(0)), ((System.Byte)(0)), "bed",
System.Data.DataRowVersion.Current, null));
odbcCommand.Parameters.Add(new
OdbcParameter("allergies", OdbcType.VarChar, 60,
System.Data.ParameterDirection.Output, false,
((System.Byte)(0)), ((System.Byte)(0)), "allergies",
System.Data.DataRowVersion.Current, null));
odbcCommand.Parameters.Add(new
OdbcParameter("Original_id", OdbcType.VarChar, 15,
System.Data.ParameterDirection.Input, false, ((System.Byte)
(0)), ((System.Byte)(0)), "id",
System.Data.DataRowVersion.Original, null));
odbcCommand.Parameters
["Original_id"].Value = original_id;
odbcCommand.Connection =
this.odbcConnection1;

this.odbcConnection1.Open();
try
{
dataReader =
odbcCommand.ExecuteReader(CommandBehavior.SingleRow);
if (dataReader.Read())
{
name =
dataReader.GetString(0);
nUnit =
dataReader.GetString(1);
dob =
dataReader.GetString(2);
room =
dataReader.GetString(3);
bed =
dataReader.GetString(4);
allergies =
dataReader.GetString(5);
Console.WriteLine
(name + ", " + nUnit + ", " + dob + ", " + room + ", " +
bed + ", " + allergies);
}
else
{
Console.WriteLine
("Fail reading from database with id = " + original_id);
}
dataReader.Close();
}
catch(Exception e1)
{
Console.WriteLine
(e1.ToString());
}

this.odbcConnection1.Close();


This is my table definition:
CREATE TABLE tblPatient
(
name VARCHAR(30) NOT NULL,
id VARCHAR(15) NOT NULL,
nUnit VARCHAR(10) NOT NULL,
room VARCHAR(10) NOT NULL,
bed VARCHAR(2) NOT NULL,
allergies VARCHAR(60) NOT NULL,
PRIMARY KEY( id )
);

Thanks in advance for you help.
Thuy (twee)


1 Answer

Thuy Nguyen

5/3/2002 2:26:00 AM

0

Thanks for replying so quickly. But when I used just one
single parameter, in this case, "id", I get the following
exception:
*****
ERROR [07002] [Sybase][ODBC Driver][Adaptive Server
Anywhere]Count field incorrect: Not enough values for host
variables
****

so that was why I set all those parameters. BTW: My
ExecuteScalar() for a single return value works with no
problem...



>-----Original Message-----
>Thuy,
>
>I see several problems here. Your Select statement takes
just one parameter and you are passing several output
parameters for all the fields in your select
>statement. I haven'e seen this before but all what you
need is just the last parameter. I'm not sure of the
syntax you are using for the Input parameter but here is
>an example:
>
> odbcCommand.Parameters.Add("Original_id",
OdbcType.Char, 5);
> odbcCommand.Parameters
["Original_id"].Value = original_id;
>
>
>
>Thanks,
>Hussein Abuthuraya
>Microsoft Developer Support
>
>This posting is provided "AS IS" with no warranties, and
confers no rights. You assume all risk for your use. ©
2002 Microsoft Corporation. All rights reserved
>
>Are you secure? For information about the Microsoft
Strategic Technology Protection Program and to order your
FREE Security Tool Kit, please visit
>http://www.microsoft.co....
>