Store 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 ( a); 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 "), _bstr_t (l") "), _BSTR_T (L" "), -1); cmd-> ActiveConnection = CN; cmd-> commandType = adcmdtext; cmd-> commandtext =" EXEC ZZD? ";
// Para-> name = _BSTR_T ("@ a1"); para-> type = advarbinary; para-> size = 8000; para-> direction = adpaaminput; 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 ) SafearrayPuteElement (PSA, & I, & PCHAR);
Variant varob; varblob.vt = vt_Array | VT_UI1; // Varblob type Set to Byte type array varblob.Parray = PSA; Para-> value = varblob; cmd-> parameters-> append (para); cmd-> execute (Null, null, adcmdtext);} catch (_COM_ERROR & E) {_BSTR_T BSTROR = E.DESCRIPTION (); cstract m_strerror = (lpctstr) bstrerror;
} IF (PSA! = NULL) {SafeArrayDestroy (PSA);} if (cmd! = Null) {cmd = null;} if (cn! = Null) {cn-> close (); cn = null;}} counitialize ();