Click here to Skip to main content
14,328,905 members
   

C#

 
GeneralRe: Floating Point Calculations - c# vs. c++ Pin
0x01AA29-May-19 5:42
professional0x01AA29-May-19 5:42 
AnswerRe: Floating Point Calculations - c# vs. c++ Pin
#realJSOP24-May-19 0:07
mve#realJSOP24-May-19 0:07 
GeneralRe: Floating Point Calculations - c# vs. c++ Pin
0x01AA24-May-19 5:40
professional0x01AA24-May-19 5:40 
QuestionPython str.extract to c# (regex?) Pin
Member 1441807322-May-19 2:15
memberMember 1441807322-May-19 2:15 
AnswerRe: Python str.extract to c# (regex?) Pin
Nathan Minier22-May-19 2:40
professionalNathan Minier22-May-19 2:40 
GeneralRe: Python str.extract to c# (regex?) Pin
Member 1441807323-May-19 3:56
memberMember 1441807323-May-19 3:56 
QuestionComboBox not refreshing error. Pin
Khandkar Asif Hossain21-May-19 9:20
memberKhandkar Asif Hossain21-May-19 9:20 
AnswerRe: ComboBox not refreshing error. Pin
Richard Deeming21-May-19 9:28
mveRichard Deeming21-May-19 9:28 
First off, don't do it like that. Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]

Secondly, there's no need for the nested query; just use TOP 1 with an ORDER BY:
using (var connection = new SqlConnection("..."))
using (var command = new SqlCommand("SELECT TOP 1 Balance FROM [Interest Posting] WHERE [Member ID] = @MemberID ORDER BY [Input Date] DESC", connection))
{
    command.Parameters.AddWithValue("@MemberID", cb_MemberID.SelectedValue);
    
    connection.Open();
    object result = command.ExecuteScalar();
    if (Convert.IsDBNull(result))
    {
        // There is no balance for the member...
    }
    else
    {
        decimal balance = Convert.ToDecimal(result);
        // Display the balance...
    }
}

If at all possible, you should look at renaming your tables and columns so that they don't contain spaces. Stick to unaccented English letters, numbers, and optionally underscores (_). It will make your queries much easier to write.
Rules for Regular Identifiers - Database Identifiers - SQL Server | Microsoft Docs[^]



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

GeneralRe: ComboBox not refreshing error. Pin
Khandkar Asif Hossain22-May-19 7:40
memberKhandkar Asif Hossain22-May-19 7:40 
AnswerRe: ComboBox not refreshing error. Pin
Luc Pattyn21-May-19 9:36
professionalLuc Pattyn21-May-19 9:36 
QuestionResize all controls on a user control or form automatically with changing of user control or form Pin
Member 1332584617-May-19 16:47
memberMember 1332584617-May-19 16:47 
AnswerRe: Resize all controls on a user control or form automatically with changing of user control or form Pin
OriginalGriff17-May-19 19:26
protectorOriginalGriff17-May-19 19:26 
GeneralRe: Resize all controls on a user control or form automatically with changing of user control or form Pin
Member 1332584618-May-19 4:43
memberMember 1332584618-May-19 4:43 
GeneralRe: Resize all controls on a user control or form automatically with changing of user control or form Pin
OriginalGriff18-May-19 4:58
protectorOriginalGriff18-May-19 4:58 
GeneralRe: Resize all controls on a user control or form automatically with changing of user control or form Pin
Member 1332584618-May-19 11:06
memberMember 1332584618-May-19 11:06 
GeneralRe: Resize all controls on a user control or form automatically with changing of user control or form Pin
OriginalGriff18-May-19 20:57
protectorOriginalGriff18-May-19 20:57 
GeneralRe: Resize all controls on a user control or form automatically with changing of user control or form Pin
Member 1332584619-May-19 17:09
memberMember 1332584619-May-19 17:09 
GeneralRe: Resize all controls on a user control or form automatically with changing of user control or form Pin
Dave Kreskowiak20-May-19 2:37
mveDave Kreskowiak20-May-19 2:37 
AnswerRe: Resize all controls on a user control or form automatically with changing of user control or form Pin
#realJSOP18-May-19 1:06
mve#realJSOP18-May-19 1:06 
GeneralRe: Resize all controls on a user control or form automatically with changing of user control or form Pin
Member 1332584618-May-19 4:35
memberMember 1332584618-May-19 4:35 
GeneralRe: Resize all controls on a user control or form automatically with changing of user control or form Pin
#realJSOP18-May-19 6:47
mve#realJSOP18-May-19 6:47 
GeneralRe: Resize all controls on a user control or form automatically with changing of user control or form Pin
phil.o18-May-19 6:48
mvephil.o18-May-19 6:48 
AnswerRe: Resize all controls on a user control or form automatically with changing of user control or form Pin
Gerry Schmitz18-May-19 7:11
mveGerry Schmitz18-May-19 7:11 
GeneralRe: Resize all controls on a user control or form automatically with changing of user control or form Pin
Member 1332584618-May-19 10:49
memberMember 1332584618-May-19 10:49 
NewsRe: Resize all controls on a user control or form automatically with changing of user control or form Pin
Mycroft Holmes18-May-19 12:04
memberMycroft Holmes18-May-19 12:04 

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.