Error: Failed to convert parameter value from a String to a Byte[]. (Need Help Urgently)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Here is the code for executing stored procedure ExecuteSP() [no
prob. with that] , and object that sets all its parameters in other
functions and the stored procedure. I think it has something to do
with db datatypes since this is the first time, i am working with
databases and not really much of an expert.

How can I rectify it? One thing more...... Should I be passing a
value to type bit in sql server as 0 or '0'..... '0' is for character
i guess

private static Object ExecuteSP(Object[] argArray)
{
SqlCommand sqlcmd = new SqlCommand();
SqlConnection sqlconnection1 = new
SqlConnection(connectionString);
sqlcmd.Connection = sqlconnection1;
Object returnValue;
int paramCount = (int)argArray[1]; // the number of
parameters
sqlcmd.CommandText = (string)argArray[2]; // the whole
query
sqlcmd.CommandType =
CommandType.StoredProcedure;

for (int j = 0, i = 3; j < paramCount; i += 4, j++)
{
SqlParameter myPrm = new
SqlParameter((string)argArray[i],

(SqlDbType)argArray[i + 1],

(int)argArray[i + 2]);
myPrm.Value = argArray[i + 3];
sqlcmd.Parameters.Add(myPrm);
}

sqlconnection1.Open();

if ((int)argArray[0] == 0)
returnValue = sqlcmd.ExecuteNonQuery(); //
returns the number of rows affected
if ((int)argArray[0] == 1)
returnValue = sqlcmd.ExecuteScalar(); //
returns a single value
else
returnValue =
sqlcmd.ExecuteReader(CommandBehavior.CloseConnection); //returns
multiple values

return returnValue;

}

static public bool InsertTuple(string Password,DateTime
PassLastChanged,string Firstname,string Lastname,string telno,
DateTime dob,string Address,string
Accno,string Pincode,string Username,
string Secques,string Secans,string
img1,string img2,string img3)
{
object[] prms = new object[63];

prms[0] = 1;
prms[1] = 15;
prms[2] = "REGISTRATION";
prms[3] = "@PASSWORD";
prms[4] = SqlDbType.VarChar;
prms[5] = 30;
prms[6] = Password;
prms[7] = "@PASSLASTCHANGED";
prms[8] = SqlDbType.DateTime;
prms[9] = 30;
prms[10] = PassLastChanged;
prms[11] = "@FIRSTNAME";
prms[12] = SqlDbType.VarChar;
prms[13] = 50;
prms[14] = Firstname;
prms[15] = "@LASTNAME";
prms[16] = SqlDbType.VarChar;
prms[17] = 50;
prms[18] = Lastname;
prms[19] = "@TELNO";
prms[20] = SqlDbType.VarChar;
prms[21] = 10;
prms[22] = telno;
prms[23] = "@DOB";
prms[24] = SqlDbType.DateTime;
prms[25] = 50;
prms[26] = dob;
prms[27] = "@ADDRESS";
prms[28] = SqlDbType.VarChar;
prms[29] = 50;
prms[30] = Address;
prms[31] = "@ACCNO";
prms[32] = SqlDbType.VarChar;
prms[33] = 4;
prms[34] = Accno;
prms[35] = "@PINCODE";
prms[36] = SqlDbType.VarChar;
prms[37] = 4;
prms[38] = Pincode;
prms[39] = "@USERNAME";
prms[40] = SqlDbType.VarChar;
prms[41] = 30;
prms[42] = Username;
prms[43] = "@SECQUES";
prms[44] = SqlDbType.VarChar;
prms[45] = 50;
prms[46] = Secques;
prms[47] = "@SECANS";
prms[48] = SqlDbType.VarChar;
prms[49] = 50;
prms[50] = Secans;
prms[51] = "@Image1";
prms[52] = SqlDbType.Image;
prms[53] = 100;
prms[54] = img1;
prms[55] = "@Image2";
prms[56] = SqlDbType.Image;
prms[57] = 100;
prms[58] = img2;
prms[59] = "@Image3";
prms[60] = SqlDbType.Image;
prms[61] = 50;
prms[62] = img3;


bool myvar = false;
Object returnValue = ExecuteSP(prms);
if (returnValue == null)
{
myvar = false;
}
else
{
myvar = (bool)returnValue;
}

return myvar;

}

ALTER PROCEDURE dbo.REGISTRATION
(
@PASSWORD VARCHAR(30),
@PASSLASTCHANGED DATETIME,
@FIRSTNAME VARCHAR(50),
@LASTNAME VARCHAR(50),
@TELNO VARCHAR(10),
@DOB DATETIME,
@ADDRESS VARCHAR(100),
@ACCNO VARCHAR(10),
@PINCODE VARCHAR(4),
@USERNAME VARCHAR(30),
@SECQUES VARCHAR(50),
@SECANS VARCHAR(50),
@Image1 Image,
@Image2 Image,
@Image3 Image
)
AS
INSERT INTO
CUSTOMER(CUSTOMER_ID,IS_LOGGED,PASSWORD,PASS_LASTCHANGED,LOCKED,CUST_FIRST_NAME,CUST_LAST_NAME,
CUST_TELNO,CUST_DOB,CUST_ADDRESS,CUST_ACC#,CUST_PINCODE,CUST_USERNAME,CUST_SECQUES,CUST_SECANS,
Image1,Image2,Image3)
VALUES(NEWID(),0,@PASSWORD,@PASSLASTCHANGED,
0,@FIRSTNAME,@LASTNAME,@TELNO,@DOB,@ADDRESS,@ACCNO,@PINCODE,
@USERNAME,@SECQUES,@SECANS,@Image1,@Image2,@Image3)
RETURN

.



Relevant Pages

  • How to pass a data structure as a stored proc parameter to a varbinary field in SQL Server 2005
    ... of type SmartCardType ... to a stored procedure using either a TADODataSet or TADOStoredProc? ... ReturnValue = GetSetValue::PrepUpdateDataset(Infinite, NoSleep, ... ftBoolean, pdInput, sizeof, PassedMemoryTest); ...
    (borland.public.delphi.database.ado)
  • Re: Output Parameter?
    ... Type is output, not returnvalue. ... whether the UserID supplied by the new record already exists or not. ... stored procedure is 1, it means that the UserID already exists. ... Dim sqlConn As SqlConnection ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Retrieving the @@IDENTITY value from a SP in VB.Net
    ... Set the direction to .ReturnValue to get the RETURN value. ... See my articles on handling @@Identity and stored procedure parameters. ... >> Dim cn As New SqlConnection ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Problem writing XML files.
    ... What the stored procedure does is, ... > NTEXT/ IMAGE type to write the files but they give me errors which, ... > @ReturnValue as image OUT ... > DECLARE @strVar as varchar ...
    (comp.databases.ms-sqlserver)
  • Re: Variable Question
    ... > stored procedure. ... Create Proc Testing ... @MyVar varcharOUTPUT ...
    (microsoft.public.sqlserver.programming)