Click here to Skip to main content
14,391,186 members
   

C#

 
GeneralRe: Reading Access Into SQL - OLE Provider Errors Pin
Eddy Vluggen6-Oct-19 7:52
mveEddy Vluggen6-Oct-19 7:52 
GeneralRe: Reading Access Into SQL - OLE Provider Errors Pin
Dave Kreskowiak6-Oct-19 9:47
mveDave Kreskowiak6-Oct-19 9:47 
GeneralRe: Reading Access Into SQL - OLE Provider Errors Pin
Kevin Marois6-Oct-19 9:51
professionalKevin Marois6-Oct-19 9:51 
AnswerRe: Reading Access Into SQL - OLE Provider Errors Pin
Gerry Schmitz4-Oct-19 11:22
mveGerry Schmitz4-Oct-19 11:22 
GeneralRe: Reading Access Into SQL - OLE Provider Errors Pin
Kevin Marois6-Oct-19 7:16
professionalKevin Marois6-Oct-19 7:16 
QuestionImpossible d'enregistrer les données, que faire??? Pin
Joel_Bidingija3-Oct-19 14:24
MemberJoel_Bidingija3-Oct-19 14:24 
AnswerRe: Impossible d'enregistrer les données, que faire??? Pin
Dave Kreskowiak3-Oct-19 14:28
mveDave Kreskowiak3-Oct-19 14:28 
AnswerRe: Impossible d'enregistrer les données, que faire??? Pin
OriginalGriff3-Oct-19 21:03
mveOriginalGriff3-Oct-19 21: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:
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:
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;--'
Which SQL sees as three separate commands:
SELECT * FROM MyTable WHERE StreetAddress = 'x';
A perfectly valid SELECT
DROP TABLE MyTable;
A perfectly valid "delete the table" command
--'
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:
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 Vluggen4-Oct-19 0:27
mveEddy Vluggen4-Oct-19 0:27 
GeneralRe: Impossible d'enregistrer les données, que faire??? Pin
Richard MacCutchan4-Oct-19 4:13
mveRichard MacCutchan4-Oct-19 4:13 
GeneralRe: Impossible d'enregistrer les données, que faire??? Pin
Kevin Marois4-Oct-19 8:24
professionalKevin Marois4-Oct-19 8:24 
QuestionAbout Luhn Algorithm Pin
Member 146114343-Oct-19 2:44
MemberMember 146114343-Oct-19 2:44 
AnswerRe: About Luhn Algorithm Pin
Pete O'Hanlon3-Oct-19 2:53
communityengineerPete O'Hanlon3-Oct-19 2:53 
AnswerRe: About Luhn Algorithm Pin
Dave Kreskowiak3-Oct-19 2:57
mveDave Kreskowiak3-Oct-19 2:57 
AnswerRe: About Luhn Algorithm Pin
OriginalGriff3-Oct-19 5:04
mveOriginalGriff3-Oct-19 5:04 
AnswerRe: About Luhn Algorithm Pin
CPallini3-Oct-19 8:55
mveCPallini3-Oct-19 8:55 
AnswerRe: About Luhn Algorithm Pin
Kevin Marois4-Oct-19 8:27
professionalKevin Marois4-Oct-19 8:27 
QuestionGet constant from column ordinal. Pin
MAW3030-Sep-19 9:47
MemberMAW3030-Sep-19 9:47 
AnswerRe: Get constant from column ordinal. Pin
Richard MacCutchan30-Sep-19 10:17
mveRichard MacCutchan30-Sep-19 10:17 
AnswerRe: Get constant from column ordinal. Pin
BillWoodruff1-Oct-19 0:37
mveBillWoodruff1-Oct-19 0:37 
AnswerRe: Get constant from column ordinal. Pin
Luc Pattyn1-Oct-19 4:55
sitebuilderLuc Pattyn1-Oct-19 4:55 
QuestionUpload encrypted excel file to datagridview Pin
HoaiNTT061029-Sep-19 23:48
MemberHoaiNTT061029-Sep-19 23:48 
QuestionRe: Upload encrypted excel file to datagridview Pin
Richard MacCutchan29-Sep-19 23:51
mveRichard MacCutchan29-Sep-19 23:51 
JokeRe: Upload encrypted excel file to datagridview Pin
lw@zi 30-Sep-19 0:06
professional lw@zi 30-Sep-19 0:06 
AnswerRe: Upload encrypted excel file to datagridview Pin
OriginalGriff30-Sep-19 2:30
mveOriginalGriff30-Sep-19 2: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.