Stored Procedure:
Create procedure zzd
@ A1 varbinary (8000)
As
Go
C #:
Sqlconnection Cn = NULL;
Sqlcommand cmd = NULL;
Try
{
CN = new sqlconnection ();
CN. connectionstring = "Data Source = 192.168.0.199; initial catalog = Haha; user id = sa; Password = sa ";
CN. open ();
Cmd = cn. createcommand ();
Cmd. commandtype = commandtype. text;
Cmd. commandtext = "Exec zzd @ A1 ";
Sqlparameter Param = new sqlparameter ();
Param. parametername = "@ A1 ";
Param. dbtype = dbtype. Binary;
Param. Direction = parameterdirection. input;
Byte [] A = new byte [200];
Sqlbinary bin = new sqlbinary ();
Param. value = bin;
Cmd. Parameters. Add (PARAM );
Cmd. executenonquery ();
}
Catch (exception E1)
{
String A11 = e1.message;
}
If (CMD! = NULL)
Cmd = NULL;
If (CN! = NULL)
{
CN. Close ();
CN = NULL;
}
ADO:
Coinitialize (null );
{
_ Connectionptr CN;
_ Commandptr cmd;
_ Parameterptr para;
Safearray * PSA = NULL;
Para. createinstance (_ uuidof (parameter ));
Try
{
CN. createinstance (_ uuidof (connection ));
Cmd. createinstance (_ uuidof (command ));
Para. createinstance (_ uuidof (parameter ));
CN-> connectionstring = "provider = sqloledb.1; user id = sa; Password = sa; initial catalog = Haha; Data Source = 192.168.0.199 ";
CN-> open (_ bstr_t (L ""),-1 );
CMD-> activeconnection = cn;
CMD-> commandtype = ad1_text;
CMD-> commandtext = "Exec zzd? ";
// Para-> name = _ bstr_t ("@ A1 ");
Para-> type = advarbinary;
Para-> size = 8000;
Para-> direction = adparaminput;
Safearray * PSA;
Safearraybound rgsabound [1];
Rgsabound [0]. llbound = 0;
Rgsabound [0]. celements = 100;
PSA = safearraycreate (vt_ui1, 1, rgsabound); // create a safearray object
Char pchar = 'C ';
// Copy data
For (long I = 0; I <(long) 100; I ++)
Safearrayputelement (PSA, & I, & pchar );
Variant varblob;
Varblob. Vt = vt_array | vt_ui1; // sets the varblob type to an array of the byte type.
Varblob. parray = psa;
Para-> value = varblob;
CMD-> parameters-> append (para );
CMD-> execute (null, null, ad1_text );
}
Catch (_ com_error & E)
{
_ Bstr_t bstrerror = E. Description ();
Cstring m_strerror = (lpctstr) bstrerror;
}
If (PSA! = NULL)
{
Safearraydestroy (PSA );
}
If (CMD! = NULL)
{
Cmd = NULL;
}
If (CN! = NULL)
{
CN-> close ();
CN = NULL;
}
}
Couninitialize ();