Click here to Skip to main content
15,890,717 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# Help with new level start in Unity Pin
F-ES Sitecore20-May-15 22:20
professionalF-ES Sitecore20-May-15 22:20 
GeneralRe: C# Help with new level start in Unity Pin
Member 1170715120-May-15 23:46
Member 1170715120-May-15 23:46 
GeneralRe: C# Help with new level start in Unity Pin
Richard MacCutchan21-May-15 1:28
mveRichard MacCutchan21-May-15 1:28 
AnswerRe: C# Help with new level start in Unity Pin
mirdana31-May-15 21:08
mirdana31-May-15 21:08 
QuestionTCP Comm. <Data handling help needed> Pin
Member 1168908120-May-15 16:07
Member 1168908120-May-15 16:07 
AnswerRe: TCP Comm. <Data handling help needed> Pin
Richard MacCutchan20-May-15 21:29
mveRichard MacCutchan20-May-15 21:29 
QuestionRetreive blob as text SQLite Pin
DPaul199420-May-15 7:51
DPaul199420-May-15 7:51 
AnswerRe: Retreive blob as text SQLite PinPopular
Richard Deeming20-May-15 8:13
mveRichard Deeming20-May-15 8:13 
Your code is vulnerable to SQL Injection[^].

NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

You're calling Conexiune.getConnection() twice, throwing away the result of the first call, and not disposing of the result of the second call.

You should wrap your disposable objects (the connection, command, and datareader) in using blocks.

You shouldn't use SELECT * FROM - state the column(s) you want to load explicitly.

There's no need to use a datareader to select a single value. ExecuteScalar will return the first column of the first row of the query results. You can also add a LIMIT 1 at the end of the query, since you're only looking at a single record.

To convert a byte[] array to a string, you'll probably need to the Encoding class[^]. Which encoding you use will depend on how your data was added to the database.

C#
const string select = "SELECT data FROM legislatie WHERE capitol = @capitol LIMIT 1";
 
using (SqlLiteConnection connection = Conexiune.getConnection())
using (SqlLiteCommand cmd = new SqlListCommand(select, connection))
{
    cmd.Parameters.AddWithValue("@capitol", SimulatorManager.LegislatieCapitol);
    cmd.CommandType = CommandType.Text;
    
    var data = cmd.ExecuteScalar() as byte[];
    if (data == null || data.Length == 0)
    {
        richTextBox1.Text = string.Empty;
    }
    else
    {
        // TODO: Choose the correct encoding, based on how your data is stored:
        richTextBox1.Text = System.Text.Encoding.Default.GetString(data);
    }
}




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


GeneralRe: Retreive blob as text SQLite Pin
DPaul199420-May-15 8:20
DPaul199420-May-15 8:20 
Questionpropeties in consuming class Pin
Cianide20-May-15 3:49
Cianide20-May-15 3:49 
AnswerRe: propeties in consuming class Pin
Sascha Lefèvre20-May-15 4:03
professionalSascha Lefèvre20-May-15 4:03 
Questionserver and client Pin
Nick196120-May-15 2:15
Nick196120-May-15 2:15 
AnswerRe: server and client Pin
Richard MacCutchan20-May-15 2:35
mveRichard MacCutchan20-May-15 2:35 
GeneralRe: server and client Pin
Nick196120-May-15 2:48
Nick196120-May-15 2:48 
GeneralRe: server and client Pin
Nick196120-May-15 2:51
Nick196120-May-15 2:51 
GeneralRe: server and client Pin
Richard MacCutchan20-May-15 3:07
mveRichard MacCutchan20-May-15 3:07 
GeneralRe: server and client Pin
Nick196120-May-15 12:22
Nick196120-May-15 12:22 
QuestionIIS stop the webservice application when I migrated 1.1 to 4.5 framework Pin
Narayan Mitra20-May-15 1:19
Narayan Mitra20-May-15 1:19 
Questionhow retrieve image from database Binary Format Pin
Member 1168949020-May-15 0:41
Member 1168949020-May-15 0:41 
AnswerRe: how retrieve image from database Binary Format Pin
Herman<T>.Instance20-May-15 0:52
Herman<T>.Instance20-May-15 0:52 
AnswerRe: how retrieve image from database Binary Format Pin
Sascha Lefèvre20-May-15 0:55
professionalSascha Lefèvre20-May-15 0:55 
Questionclosing an application before it begins Pin
DannyGroff19-May-15 8:30
DannyGroff19-May-15 8:30 
AnswerRe: closing an application before it begins Pin
OriginalGriff19-May-15 8:57
mveOriginalGriff19-May-15 8:57 
GeneralRe: closing an application before it begins Pin
Sascha Lefèvre19-May-15 10:01
professionalSascha Lefèvre19-May-15 10:01 
GeneralRe: closing an application before it begins Pin
OriginalGriff19-May-15 10:07
mveOriginalGriff19-May-15 10:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.