Store byte array into SQL Server

  • Thread starter Thread starter Opa1
  • Start date Start date
O

Opa1

Hi,

This question has been asked b4 on these newsgroups. I can't find a
clear example.

I have a byte array called signature. I'd like to store this byte
array in a SQL server varbinary column and then read it back again. I
have the following code snippet:

Assumptions: sqlCon is a valid SQL connection initialized elsewhere

public void InsertSalesTransaction(string SalesPersonID, byte[]
signature)
{

string sCmd = "INSERT INTO SalesTransactions ";
sCmd += "(SalespersonID,Signature)";
sCmd += " VALUES ('" + SalesPersonID + "'," + ???)

SqlCommand sqlCmd = new SqlCommand (sCmd, sqlCon);
sqlCmd.ExecuteNonQuery() > 0;

}


HOW do you insert the signature byte array?

Can someone provide me with an example?

Thanks a lot
 
Opa1 said:
This question has been asked b4 on these newsgroups. I can't find a
clear example.

I have a byte array called signature. I'd like to store this byte
array in a SQL server varbinary column and then read it back again. I
have the following code snippet:

Assumptions: sqlCon is a valid SQL connection initialized elsewhere

public void InsertSalesTransaction(string SalesPersonID, byte[]
signature)
{

string sCmd = "INSERT INTO SalesTransactions ";
sCmd += "(SalespersonID,Signature)";
sCmd += " VALUES ('" + SalesPersonID + "'," + ???)

SqlCommand sqlCmd = new SqlCommand (sCmd, sqlCon);
sqlCmd.ExecuteNonQuery() > 0;

}

HOW do you insert the signature byte array?

Use a SqlParameter with a DbType of Binary, and set the value to your
byte array.

You should use parameters for the sales person ID too, ideally - that
will cope if somehow you end up with a quote in the ID, for instance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top