473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Store byte array into SQL Server

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
Nov 16 '05 #1
1 27726
Opa1 <op***********@yahoo.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
2
by: Knoxy | last post by:
Hi there, Hope someone can help. I've had a look around on the web and found some useful info but not getting this to work... seen lots of different variations PROBLEM: ======== I have a...
8
by: frekster | last post by:
Hi. I used to be able to do this easily in vb 6 via looping and preserving the source array data/size etc. How can I do this in vb.net? I've been trying for a while now and this should be...
5
by: moondaddy | last post by:
I'm caching a dataset in an asp.net session variable to hold a user's data. one data item I need to store is an image the user uploaded. My problem is that I don't know how to get the image into...
10
by: Danny | last post by:
I am working on a project where I will receive xml documents from clients machines as a byte array. They will use the web browser navigate method to post the data to my ASP.NET page. I then pick up...
1
by: radhikaullas | last post by:
Hello all In my application to store the encrypted password in sql server. i know the code for encrypt & decrypt. but the problem is the encrypt will return byte array. i dont know how to...
3
by: ist | last post by:
Hi, I am trying to get (and transfer over ASP.NET) some encrypted data from some MySQL fields. Since the data contains many unicode characters, I tried to get the data as a series of ASCII...
0
by: harshad | last post by:
Dear All,Here I am facing problem to store image.I am trying to store byte array(image) in to session variable so at time of update I will got that byte array and I do my update. here i am given...
9
by: =?Utf-8?B?U3RldmVuIFRhbmc=?= | last post by:
I want to download pfx from my asp.net server, add the pfx to client's X509Store as a trusted publisher, Is it possible? my func in aspx is like this: void InstallCertification() { try{...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.