470,588 Members | 2,126 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,588 developers. It's quick & easy.

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

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.CloseConnecti on); //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_LASTC HANGED,LOCKED,CUST_FIRST_NAME,CUST_LAST_NAME,
CUST_TELNO,CUST_DOB,CUST_ADDRESS,CUST_ACC#,CUST_PI NCODE,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

Apr 5 '07 #1
0 6281

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Wayno | last post: by
6 posts views Thread by Peter Frost | last post: by
7 posts views Thread by Leon Shaw | last post: by
5 posts views Thread by Solel Software | last post: by
3 posts views Thread by Adriano | last post: by
2 posts views Thread by DazedAndConfused | last post: by
reply views Thread by Buddy Home | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.