Click here to Skip to main content
15,899,937 members
Home / Discussions / C#
   

C#

 
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...

GeneralRe: Why do not save Login file in Server Explorer Pin
Sascha Lefèvre25-Apr-16 21:21
professionalSascha Lefèvre25-Apr-16 21:21 
GeneralRe: Why do not save Login file in Server Explorer Pin
Member 1228884026-Apr-16 5:11
Member 1228884026-Apr-16 5:11 
GeneralRe: Why do not save Login file in Server Explorer Pin
OriginalGriff26-Apr-16 5:23
mveOriginalGriff26-Apr-16 5:23 
GeneralRe: Why do not save Login file in Server Explorer Pin
Member 1228884026-Apr-16 16:21
Member 1228884026-Apr-16 16:21 
GeneralRe: Why do not save Login file in Server Explorer Pin
OriginalGriff26-Apr-16 19:58
mveOriginalGriff26-Apr-16 19:58 
GeneralRe: Why do not save Login file in Server Explorer Pin
Member 1228884027-Apr-16 4:54
Member 1228884027-Apr-16 4:54 
GeneralRe: Why do not save Login file in Server Explorer Pin
Pete O'Hanlon27-Apr-16 6:29
mvePete O'Hanlon27-Apr-16 6:29 
GeneralRe: Why do not save Login file in Server Explorer Pin
Sascha Lefèvre26-Apr-16 5:40
professionalSascha Lefèvre26-Apr-16 5:40 
GeneralRe: Why do not save Login file in Server Explorer Pin
OriginalGriff26-Apr-16 6:32
mveOriginalGriff26-Apr-16 6:32 
QuestionHelp with Listbox and comboBox Pin
Member 1231776424-Apr-16 23:40
Member 1231776424-Apr-16 23:40 
AnswerRe: Help with Listbox and comboBox Pin
koolprasad200324-Apr-16 23:55
professionalkoolprasad200324-Apr-16 23:55 
GeneralRe: Help with Listbox and comboBox Pin
Member 1231776424-Apr-16 23:56
Member 1231776424-Apr-16 23:56 
AnswerRe: Help with Listbox and comboBox Pin
BillWoodruff26-Apr-16 4:04
professionalBillWoodruff26-Apr-16 4:04 
GeneralRe: Help with Listbox and comboBox Pin
Sascha Lefèvre26-Apr-16 5:12
professionalSascha Lefèvre26-Apr-16 5:12 
QuestionHow to get/set SharePoint 2013 MySite properties through API? Pin
Coding Eyes24-Apr-16 23:32
Coding Eyes24-Apr-16 23:32 
AnswerRe: How to get/set SharePoint 2013 MySite properties through API? Pin
Eddy Vluggen25-Apr-16 3:12
professionalEddy Vluggen25-Apr-16 3:12 
QuestionHow to get selected item data of listView Column Item? Pin
0HourCoder23-Apr-16 9:36
0HourCoder23-Apr-16 9:36 

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.