Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Set a Byte Array to a SqlServer database on C++\Cli

Set a Byte Array to a SqlServer database on C++\Cli

Scheduled Pinned Locked Moved Managed C++/CLI
questioncsharpc++databasecom
2 Posts 2 Posters 7 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    betedesvosges
    wrote on last edited by
    #1

    Hello, I have a byte array that i want to set on a sqlserver database with ADO.NET. I have an error message : Cannot convert 'signed char *' to 'System::Object ^' What is wrong ? Thanks in advance.

    // Connexion
    SqlConnection ^connection = gcnew SqlConnection(connectString);
    connection->Open();
    
    // Requete
    String ^ myRequete = "UPDATE COM\_PKCS12 SET PKCS12 = @myPKCS12 WHERE ID = '" + System::Convert::ToString(id) + "'";
    
    // Objet Command
    SqlCommand ^command = gcnew SqlCommand( myRequete, connection);
    
    //Datas
    SByte \* testByteArray = pkcs12Data->array;
    
    // Parameters
    command->Parameters->Add(gcnew SqlParameter("@myPKCS12", SqlDbType::VarBinary));
    command->Parameters\["@myPKCS12"\]->Value = testByteArray;
    
    // Execution
    int affectedrows = command->ExecuteNonQuery();
    
    // Fermeture connection
    connection->Close();
    
    Richard DeemingR 1 Reply Last reply
    0
    • B betedesvosges

      Hello, I have a byte array that i want to set on a sqlserver database with ADO.NET. I have an error message : Cannot convert 'signed char *' to 'System::Object ^' What is wrong ? Thanks in advance.

      // Connexion
      SqlConnection ^connection = gcnew SqlConnection(connectString);
      connection->Open();
      
      // Requete
      String ^ myRequete = "UPDATE COM\_PKCS12 SET PKCS12 = @myPKCS12 WHERE ID = '" + System::Convert::ToString(id) + "'";
      
      // Objet Command
      SqlCommand ^command = gcnew SqlCommand( myRequete, connection);
      
      //Datas
      SByte \* testByteArray = pkcs12Data->array;
      
      // Parameters
      command->Parameters->Add(gcnew SqlParameter("@myPKCS12", SqlDbType::VarBinary));
      command->Parameters\["@myPKCS12"\]->Value = testByteArray;
      
      // Execution
      int affectedrows = command->ExecuteNonQuery();
      
      // Fermeture connection
      connection->Close();
      
      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups