Click here to Skip to main content
15,881,852 members
Home / Discussions / C#
   

C#

 
GeneralRe: Reading Access Into SQL - OLE Provider Errors Pin
Eddy Vluggen6-Oct-19 6:52
professionalEddy Vluggen6-Oct-19 6:52 
GeneralRe: Reading Access Into SQL - OLE Provider Errors Pin
Dave Kreskowiak6-Oct-19 8:47
mveDave Kreskowiak6-Oct-19 8:47 
GeneralRe: Reading Access Into SQL - OLE Provider Errors Pin
Kevin Marois6-Oct-19 8:51
professionalKevin Marois6-Oct-19 8:51 
AnswerRe: Reading Access Into SQL - OLE Provider Errors Pin
Gerry Schmitz4-Oct-19 10:22
mveGerry Schmitz4-Oct-19 10:22 
GeneralRe: Reading Access Into SQL - OLE Provider Errors Pin
Kevin Marois6-Oct-19 6:16
professionalKevin Marois6-Oct-19 6:16 
QuestionImpossible d'enregistrer les données, que faire??? Pin
Joel_Bidingija3-Oct-19 13:24
Joel_Bidingija3-Oct-19 13:24 
AnswerRe: Impossible d'enregistrer les données, que faire??? Pin
Dave Kreskowiak3-Oct-19 13:28
mveDave Kreskowiak3-Oct-19 13:28 
AnswerRe: Impossible d'enregistrer les données, que faire??? Pin
OriginalGriff3-Oct-19 20:03
mveOriginalGriff3-Oct-19 20:03 
Don't do it like that!
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?
Fix that throughout your app and your problem will likely go away at the same time.

But ... that code won't even compile - You've grabbed some VB code and dumped it into a C# app and just hoped like heck that adding a single semicolon will make it work. It won't: "'" is the VB comment marker, "//" is the C#, every line needs a semicolon to terminate it, and the VB was written by an idiot.
Always list the columns you want to INSERT into:
SQL
INSERT INTO myTable (myColumn1, myColumn2) VALUES (@C1, @C2)
|If you don't, then SQL tries to insert them in the current table order, which means two things:
1) If the table order changes, your DB gets corrupted and that gets very difficult to fix quickly, but isn't generally spotted for a while - so by the time you get round to uncorrupting it, it's too badly mixed to be automatically fixed.
2) If you have an IDENTITY field for the Row ID, the INSERT will fail as SQL won;t let you write into it.
Even if it's currently "commented out", an empty catch block is nasty - it's a VB programmer way to not get error messages, so you don't realize that you've got a problem until it's too late. Always report or log errors so you can see what happened when teh problem become so noticeable that you have to fix them ...
Do yourself a favour, and stop using Visual Studio default names for everything - you may remember that "TextBox8" is the mobile number today, but when you have to modify it in three weeks time, will you then? Use descriptive names - "tbMobileNo" for example - and your code becomes easier to read, more self documenting, easier to maintain - and surprisingly quicker to code because Intellisense can get to to "tbMobile" in three keystrokes, where "TextBox8" takes thinking about and 8 keystrokes...
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!

GeneralRe: Impossible d'enregistrer les données, que faire??? Pin
Eddy Vluggen3-Oct-19 23:27
professionalEddy Vluggen3-Oct-19 23:27 
GeneralRe: Impossible d'enregistrer les données, que faire??? Pin
Richard MacCutchan4-Oct-19 3:13
mveRichard MacCutchan4-Oct-19 3:13 
GeneralRe: Impossible d'enregistrer les données, que faire??? Pin
Kevin Marois4-Oct-19 7:24
professionalKevin Marois4-Oct-19 7:24 
QuestionAbout Luhn Algorithm Pin
Member 146114343-Oct-19 1:44
Member 146114343-Oct-19 1:44 
AnswerRe: About Luhn Algorithm Pin
Pete O'Hanlon3-Oct-19 1:53
mvePete O'Hanlon3-Oct-19 1:53 
AnswerRe: About Luhn Algorithm Pin
Dave Kreskowiak3-Oct-19 1:57
mveDave Kreskowiak3-Oct-19 1:57 
AnswerRe: About Luhn Algorithm Pin
OriginalGriff3-Oct-19 4:04
mveOriginalGriff3-Oct-19 4:04 
AnswerRe: About Luhn Algorithm Pin
CPallini3-Oct-19 7:55
mveCPallini3-Oct-19 7:55 
AnswerRe: About Luhn Algorithm Pin
Kevin Marois4-Oct-19 7:27
professionalKevin Marois4-Oct-19 7:27 
QuestionGet constant from column ordinal. Pin
MAW3030-Sep-19 8:47
MAW3030-Sep-19 8:47 
AnswerRe: Get constant from column ordinal. Pin
Richard MacCutchan30-Sep-19 9:17
mveRichard MacCutchan30-Sep-19 9:17 
AnswerRe: Get constant from column ordinal. Pin
BillWoodruff30-Sep-19 23:37
professionalBillWoodruff30-Sep-19 23:37 
AnswerRe: Get constant from column ordinal. Pin
Luc Pattyn1-Oct-19 3:55
sitebuilderLuc Pattyn1-Oct-19 3:55 
QuestionUpload encrypted excel file to datagridview Pin
HoaiNTT061029-Sep-19 22:48
HoaiNTT061029-Sep-19 22:48 
QuestionRe: Upload encrypted excel file to datagridview Pin
Richard MacCutchan29-Sep-19 22:51
mveRichard MacCutchan29-Sep-19 22:51 
JokeRe: Upload encrypted excel file to datagridview Pin
dan!sh 29-Sep-19 23:06
professional dan!sh 29-Sep-19 23:06 
AnswerRe: Upload encrypted excel file to datagridview Pin
OriginalGriff30-Sep-19 1:30
mveOriginalGriff30-Sep-19 1:30 

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.