0

Im building a receipt which are sent to a receipt printer through ESC/Pos. If I later on need to print out a copy of that receipt I need to store the esc/pos commands in a database. This is where my problem starts because I cant find a proper datatype to store the receipt in.

How do you store your receipt copies? Strings? Varbinarys? Anything else?

UPDATE: Im sorry. I wrote a fast example of how ESC/Pos works.

        Encoding enc = Encoding.ASCII;

        string text = string.Empty;
        text += Convert.ToChar(27) + "@"; 
        text += Convert.ToChar(27) + "R" + Convert.ToChar(9);
        text += Convert.ToChar(27) + "t" + Convert.ToChar(5);

        for (int i = 255; i < 300; i++)
        {
            text += i + " " + Convert.ToChar(i) + Environment.NewLine;
        }
        for (int i = 0; i < 4; i++)
            text += Environment.NewLine;
        text += Convert.ToChar(29) + "V" + Convert.ToChar(65) + Convert.ToChar(0);
        clientSock.Send(enc.GetBytes(text.ToCharArray()));

This is what I want to store. I dont wanna save just the content in the text-variable since I would loose the format that might be included in the content. Im using Microsoft SQL Server (T-SQL).

DaveL
  • 77
  • 1
  • 4
  • 13
  • Not being familiar with this (as I suspects others as well), can you post some details such as [a] a sample of the data [b] which database server you are using – Burhan Khalid Jun 11 '14 at 11:11
  • Yes of course! I'm sorry I didnt include it earlier. I updated the question now. – DaveL Jun 11 '14 at 11:45

1 Answers1

0

It looks like you need to store at least some non-printable characters so you don't want to use strings/varchar. Also, varbinary are limited to 254 bytes so you are probably better off using a blob.

Also, just fyi, you should consider using a StringBuilder instead of doing all of the string concatenation. It will be much faster.

Mark Wagoner
  • 1,729
  • 1
  • 13
  • 20
  • Thanks alot for your answer! I was looking for BLOB among the datatypes but it wasn't there. Can you think of an alternative? Also, thanks for notyfying on the concatenation! – DaveL Jun 11 '14 at 12:04
  • Actually I did some more googling and it appears I misspoke. The docs are little confusing but I think a varbinary variable (within T-SQL) is limited to 254 bytes. A varbinary column can be up to 2^31-1 bytes according to this http://msdn.microsoft.com/en-us/library/ms188362.aspx – Mark Wagoner Jun 11 '14 at 13:33
  • But the varbinary doesnt seem to store all the characters, only the printable ones – DaveL Jun 12 '14 at 06:36
  • What method do I use in c# if I want to convert it to a byte[] again? (from varbinary). Cause I dont get varbinary to work. It only stores the printable characters. Maybe you can give an example? – DaveL Jun 12 '14 at 06:58
  • http://stackoverflow.com/questions/4959253/converting-sql-server-varbinary-data-into-string-c-sharp – Mark Wagoner Jun 12 '14 at 11:49