Click here to Skip to main content
14,364,290 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi friends,

i have a problem i didnt solve 3days,

i get data from oracle database with down codes. but when i changed checkbox selection then datagridvew add column right .

not in order pf query

What I have tried:

 ma = "SYS19.MUHTM001_PKG.GETAD(MUHKOD)"
            If ayb.Checked = True Then kosul = "TO_CHAR(TARIH,'MM'),SYS19.MUHTM001_PKG.GETAD(MUHKOD)"
            If fb.Checked = True Then kosul = " TARIH,SYS19.MUHTM001_PKG.GETAD(MUHKOD),FISNO "
            If gunb.Checked = True Then kosul = " TARIH,SYS19.MUHTM001_PKG.GETAD(MUHKOD)" : gunkosul = " AND TO_CHAR(TARIH,'MM') =" & AY.Text & " "


            sorgu = " SELECT " & kosul & ", " & borç & "," & alacak & " ," & Borçbakiye & "," & alacakbakiye & "" & _
" FROM SYS19.MUHTD002 WHERE  BIRIM NOT IN ('999','998') " & gunkosul & " " & _
" AND TARIH BETWEEN '" & ilktar.Text & "' AND '" & sontar.Text & "'  " & _
" AND MUHKOD LIKE '" & muhkod.Text & "%'  GROUP BY " & kosul & "  ORDER BY " & kosul & " "
            myConn.Open()
Posted
Updated 1-Nov-19 3:59am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Not 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?
   
Comments
Member 14588284 1-Nov-19 8:59am
   
hi,
i dont use
DROP TABLE MyTable
codes ?
i don understand this? my database deletin when i use this codes?

my all querys i dont use any code except "select"
OriginalGriff 1-Nov-19 9:12am
   
Read what I said again.
Your code uses string concatenation; the above explains why that is a very, very bad idea and what you need to do to your whole app to prevent it.

Also see here:
https://xkcd.com/327/
And don't just assume it's a joke!
Member 14588284 1-Nov-19 9:16am
   
so i must use for all options different querys?
isnt it
OriginalGriff 1-Nov-19 9:26am
   
No, read what I said!
You need to use parameterised queries *at all times*.
Member 14588284 1-Nov-19 9:44am
   
OK THANS
OriginalGriff 1-Nov-19 9:45am
   
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100