Click here to Skip to main content
15,887,446 members
Home / Discussions / C#
   

C#

 
AnswerRe: Is it possible to update content of an xml file in DropBox using DropBox API? Pin
Dave Kreskowiak2-Jul-21 19:08
mveDave Kreskowiak2-Jul-21 19:08 
QuestionHow to add frame and Label controls at the same time by clicking a button in Xamarin? Pin
Alex Dunlop1-Jul-21 6:44
Alex Dunlop1-Jul-21 6:44 
AnswerRe: How to add frame and Label controls at the same time by clicking a button in Xamarin? Pin
Gerry Schmitz1-Jul-21 7:20
mveGerry Schmitz1-Jul-21 7:20 
GeneralRe: How to add frame and Label controls at the same time by clicking a button in Xamarin? Pin
Alex Dunlop1-Jul-21 7:27
Alex Dunlop1-Jul-21 7:27 
Questionshow the Name of ID datagridView cell0 to cell1 Pin
remiki1-Jul-21 0:21
remiki1-Jul-21 0:21 
AnswerRe: show the Name of ID datagridView cell0 to cell1 Pin
Richard Deeming1-Jul-21 0:46
mveRichard Deeming1-Jul-21 0:46 
GeneralRe: show the Name of ID datagridView cell0 to cell1 Pin
remiki1-Jul-21 1:31
remiki1-Jul-21 1:31 
AnswerRe: show the Name of ID datagridView cell0 to cell1 Pin
OriginalGriff1-Jul-21 1:02
mveOriginalGriff1-Jul-21 1:02 
That's some odd code ... but ...

Never 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. Always use Parameterized queries instead.

When you concatenate strings, you cause problems because SQL receives commands like:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'
The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;--'
Which SQL sees as three separate commands:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';
A perfectly valid SELECT
SQL
DROP TABLE MyTable;
A perfectly valid "delete the table" command
SQL
--'
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.

So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?

When you've fixed that through your whole app, start looking at that code.
Why are you reading each grade separately? Just issue one SQL command and read the lot - use a DataAdapter and read it all into a DataTable - then use that data to fill each row.
What you are doing is causing a heck of a lot of work for both your system and the DB Server, and you aren't even checking to see if any matching row exists!
You aren't disposing - or even closing - the connection: put that in a using block and teh system will "tidy up" behind you.
Your finally block is irrelevant, since you don't do anything in it!

And ... why are you adding rows to the DGV that you are using to limit how many times you go round the loop? That will never end until something somewhere fails - and then you will get message box after message box because it's in a try...catch inside the loop!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!

QuestionHow to count Label controls count in Xamarin? Pin
Alex Dunlop29-Jun-21 4:56
Alex Dunlop29-Jun-21 4:56 
AnswerRe: How to count Label controls count in Xamarin? Pin
Richard Deeming29-Jun-21 5:24
mveRichard Deeming29-Jun-21 5:24 
QuestionPassing parameter from one page to another Pin
Alex Dunlop28-Jun-21 6:59
Alex Dunlop28-Jun-21 6:59 
AnswerRe: Passing parameter from one page to another Pin
Gerry Schmitz28-Jun-21 7:02
mveGerry Schmitz28-Jun-21 7:02 
GeneralRe: Passing parameter from one page to another Pin
Alex Dunlop28-Jun-21 7:08
Alex Dunlop28-Jun-21 7:08 
GeneralRe: Passing parameter from one page to another Pin
Gerry Schmitz28-Jun-21 7:29
mveGerry Schmitz28-Jun-21 7:29 
GeneralRe: Passing parameter from one page to another Pin
Alex Dunlop28-Jun-21 7:34
Alex Dunlop28-Jun-21 7:34 
GeneralRe: Passing parameter from one page to another Pin
Gerry Schmitz28-Jun-21 8:02
mveGerry Schmitz28-Jun-21 8:02 
GeneralRe: Passing parameter from one page to another Pin
Richard Andrew x6428-Jun-21 14:23
professionalRichard Andrew x6428-Jun-21 14:23 
GeneralRe: Passing parameter from one page to another Pin
Richard MacCutchan28-Jun-21 21:13
mveRichard MacCutchan28-Jun-21 21:13 
GeneralRe: Passing parameter from one page to another Pin
Alex Dunlop29-Jun-21 4:53
Alex Dunlop29-Jun-21 4:53 
GeneralRe: Passing parameter from one page to another Pin
Richard MacCutchan29-Jun-21 5:44
mveRichard MacCutchan29-Jun-21 5:44 
QuestionCreate the same but in windows form C# Pin
Luis M. Rojas25-Jun-21 6:16
Luis M. Rojas25-Jun-21 6:16 
AnswerRe: Create the same but in windows form C# Pin
OriginalGriff25-Jun-21 6:23
mveOriginalGriff25-Jun-21 6:23 
QuestionDifficulty adding code to reject non numeric user inputs Pin
Member 1524886723-Jun-21 5:58
Member 1524886723-Jun-21 5:58 
AnswerRe: Difficulty adding code to reject non numeric user inputs Pin
OriginalGriff23-Jun-21 6:08
mveOriginalGriff23-Jun-21 6:08 
GeneralRe: Difficulty adding code to reject non numeric user inputs Pin
Member 1524886723-Jun-21 7:15
Member 1524886723-Jun-21 7:15 

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.