Click here to Skip to main content
15,913,277 members
Home / Discussions / C#
   

C#

 
QuestionC# Pin
Member 1248659326-Apr-16 7:45
Member 1248659326-Apr-16 7:45 
AnswerRe: C# Pin
OriginalGriff26-Apr-16 8:30
mveOriginalGriff26-Apr-16 8:30 
SuggestionRe: C# Pin
Sascha Lefèvre26-Apr-16 9:23
professionalSascha Lefèvre26-Apr-16 9:23 
GeneralRe: C# Pin
Pete O'Hanlon26-Apr-16 9:31
mvePete O'Hanlon26-Apr-16 9:31 
GeneralRe: C# Pin
Matt T Heffron26-Apr-16 10:22
professionalMatt T Heffron26-Apr-16 10:22 
GeneralRe: C# Pin
Pete O'Hanlon26-Apr-16 10:58
mvePete O'Hanlon26-Apr-16 10:58 
GeneralRe: C# Pin
Sascha Lefèvre26-Apr-16 12:01
professionalSascha Lefèvre26-Apr-16 12:01 
SuggestionRe: C# Pin
Richard Deeming27-Apr-16 1:47
mveRichard Deeming27-Apr-16 1:47 
GeneralRe: C# Pin
Sascha Lefèvre27-Apr-16 1:49
professionalSascha Lefèvre27-Apr-16 1:49 
QuestionCapture exceptions and handle those in my custom error handler Pin
Member 1204569226-Apr-16 5:37
Member 1204569226-Apr-16 5:37 
AnswerRe: Capture exceptions and handle those in my custom error handler Pin
Eddy Vluggen26-Apr-16 5:48
professionalEddy Vluggen26-Apr-16 5:48 
QuestionStudent admin management system C# console Pin
Member 1248538426-Apr-16 5:19
Member 1248538426-Apr-16 5:19 
QuestionRe: Student admin management system C# console Pin
Richard MacCutchan26-Apr-16 5:26
mveRichard MacCutchan26-Apr-16 5:26 
AnswerRe: Student admin management system C# console Pin
Eddy Vluggen26-Apr-16 5:55
professionalEddy Vluggen26-Apr-16 5:55 
GeneralRe: Student admin management system C# console Pin
Member 1248538426-Apr-16 7:48
Member 1248538426-Apr-16 7:48 
QuestionRe: Student admin management system C# console Pin
Eddy Vluggen26-Apr-16 8:25
professionalEddy Vluggen26-Apr-16 8:25 
GeneralRe: Student admin management system C# console Pin
Matt T Heffron26-Apr-16 7:54
professionalMatt T Heffron26-Apr-16 7:54 
AnswerRe: Student admin management system C# console Pin
Member 1507847221-Feb-21 3:00
Member 1507847221-Feb-21 3:00 
AnswerRe: Student admin management system C# console Pin
Member 1507847221-Feb-21 3:12
Member 1507847221-Feb-21 3:12 
AnswerRe: Student admin management system C# console Pin
Member 1563833516-May-22 9:50
Member 1563833516-May-22 9:50 
QuestionImplicit conversion to generic Interface fails Pin
mirdana26-Apr-16 0:58
mirdana26-Apr-16 0:58 
AnswerRe: Implicit conversion to generic Interface fails Pin
Richard Deeming26-Apr-16 1:24
mveRichard Deeming26-Apr-16 1:24 
GeneralRe: Implicit conversion to generic Interface fails Pin
mirdana26-Apr-16 19:01
mirdana26-Apr-16 19:01 
QuestionWhy do not save Login file in Server Explorer Pin
Member 1228884025-Apr-16 13:24
Member 1228884025-Apr-16 13:24 
AnswerRe: Why do not save Login file in Server Explorer PinPopular
OriginalGriff25-Apr-16 19:55
mveOriginalGriff25-Apr-16 19:55 
So you have one user, and his username is "textUsername.Text", and an SQL system that doesn't mind errors?
Look at your code:
C#
SqlDataAdapter sda = new SqlDataAdapter("select count(*) from Login Whare Username = textUsername.Text ; Password = textPassword.Text; +", conn);
DataTable dt = new System.Data.DataTable();
Dump some of it to make it more obvious:
C#
string s = "select count(*) from Login Whare Username = textUsername.Text ; Password = textPassword.Text; +";
And you have "just" the SQL you are getting the server to execute.

1) WHERE is spelled with an 'E', not an 'A':
SQL
from Login Whare Username

2) This inserts the name of your controls into the command, rather than the contents the user entered. Even if you fix the WHARE problem, it won't work.
3) Semicolon is a statement terminator in SQL, not an item separator:
SQL
Whare Username = textUsername.Text ; Password = textPassword.Text

Probably you wanted to say AND instead of ';'
4) What does '+' do as an SQL command? Nothing - it will be an unexpected character.
5) Even if it did work, never store passwords in clear text! It is a major security risk. There is some information on how to do it here: Password Storage: How to do it.[^] Also see here: Code Crime 1[^]
6) Don't hard code connection strings: They should be in settings files, not in the code.
7) Attaching a DB file is a bad, bad idea. It starts a new instance of your local DB server and will only work with Local SQL Express installations - it's also very much inefficient.
Make the DB a part of SQL by creating it in SQL and let it manage it.
8) SQL Connections and so forth are a scarce resource - and you are responsible for clearing up after yourself. Always Dispose of them when you are finished with them.
9) Fix all that, and your code is going to be vulnerable to SQL Injection. Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.

Follow the link at (5) and you will see much better code to do all this.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...

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.