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

C#

 
GeneralRe: catch tabpage change Pin
Heath Stewart19-Feb-04 3:30
protectorHeath Stewart19-Feb-04 3:30 
Generalpictures in a datagrid Pin
troels_sorensen17-Feb-04 3:38
troels_sorensen17-Feb-04 3:38 
GeneralRe: pictures in a datagrid Pin
Heath Stewart17-Feb-04 4:21
protectorHeath Stewart17-Feb-04 4:21 
Questionneed sql query? Pin
murali_utr17-Feb-04 3:19
murali_utr17-Feb-04 3:19 
AnswerRe: need sql query? Pin
Heath Stewart17-Feb-04 4:33
protectorHeath Stewart17-Feb-04 4:33 
Questionwhats wrong? Pin
ASGill17-Feb-04 2:16
ASGill17-Feb-04 2:16 
AnswerRe: whats wrong? Pin
Uwe Keim17-Feb-04 3:01
sitebuilderUwe Keim17-Feb-04 3:01 
AnswerRe: whats wrong? Pin
Heath Stewart17-Feb-04 3:15
protectorHeath Stewart17-Feb-04 3:15 
Didn't I tell you before that you shouldn't use string concatenation for SQL queries? What in the hell do you think the OleDbParameter and SqlParameter are for? ADO.NET introduces parameterized expressions which take ALL of the encoding work out of your application. Got a quote in one of your variables? With your way, you have to parse your values and make sure they quotes are escaped or encoded. With parameterized queries, you don't have to worry about it. Besides, massive string concatenation like you're doing is a drastic performance decrease, resulting in (m-1)O(2n) times where m is the number of strings and n is the characters in each string.

See the OleDbParameter[^] class documentation in the .NET Framework SDK for more information and an example. Most likely, not escaping or encoding your string values is what's causing that error since the string is generated and sent to the database engine AS IS.

Also, don't prompt the user before executing the query! First of all, it's annoying. Second of all, if you open the connection before prompting and they don't respond for a while (why would they think they need to answer such a stupid dialog - no other program does it; they just work). The connection gets closed and your call to ExecuteNonQuery throws an exception. Also, put your connection.Close in the finally block to make sure it gets closed on success or failure (exception). Microsoft has recommended this time and time again if you actually read the .NET Framework SDK. The finally block will always run regardless of whether or not an exception was thrown (always except for when Environment.Exit is called, which unloads the CLR - and your application - immediately).

 

Microsoft MVP, Visual C#
My Articles
GeneralCustom ListBox.Items Pin
Simon Wren17-Feb-04 2:11
professionalSimon Wren17-Feb-04 2:11 
GeneralRe: Custom ListBox.Items Pin
Heath Stewart17-Feb-04 4:52
protectorHeath Stewart17-Feb-04 4:52 
GeneralWinForms: SuspendLayout on Application Pin
troels_sorensen17-Feb-04 2:06
troels_sorensen17-Feb-04 2:06 
GeneralRe: WinForms: SuspendLayout on Application Pin
Heath Stewart17-Feb-04 4:54
protectorHeath Stewart17-Feb-04 4:54 
QuestionResize all items? Pin
thomasa17-Feb-04 1:51
thomasa17-Feb-04 1:51 
AnswerRe: Resize all items? Pin
Heath Stewart17-Feb-04 4:57
protectorHeath Stewart17-Feb-04 4:57 
GeneralRe: Resize all items? Pin
je_gonzalez17-Feb-04 17:28
je_gonzalez17-Feb-04 17:28 
GeneralRe: Resize all items? Pin
Heath Stewart17-Feb-04 19:35
protectorHeath Stewart17-Feb-04 19:35 
GeneralRe: Resize all items? Pin
je_gonzalez18-Feb-04 3:20
je_gonzalez18-Feb-04 3:20 
AnswerRe: Resize all items? Pin
je_gonzalez17-Feb-04 17:21
je_gonzalez17-Feb-04 17:21 
GeneralProblems with thread cancellation. Pin
Chen Pang17-Feb-04 1:21
Chen Pang17-Feb-04 1:21 
GeneralRe: Problems with thread cancellation. Pin
Corinna John17-Feb-04 1:41
Corinna John17-Feb-04 1:41 
GeneralRe: Problems with thread cancellation. Pin
Chen Pang17-Feb-04 1:53
Chen Pang17-Feb-04 1:53 
QuestionException Handling . To throw or not to throw? Pin
bzurer17-Feb-04 1:05
bzurer17-Feb-04 1:05 
AnswerRe: Exception Handling . To throw or not to throw? Pin
Jonathan de Halleux17-Feb-04 1:13
Jonathan de Halleux17-Feb-04 1:13 
GeneralRe: Exception Handling . To throw or not to throw? Pin
bzurer17-Feb-04 1:50
bzurer17-Feb-04 1:50 
GeneralRe: Exception Handling . To throw or not to throw? Pin
Jonathan de Halleux17-Feb-04 2:09
Jonathan de Halleux17-Feb-04 2:09 

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.