Click here to Skip to main content
15,860,972 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: Angular service error http 400 using .Net core api to accept json, escaped quotes crashing api Pin
Richard Deeming29-Jun-20 23:42
mveRichard Deeming29-Jun-20 23:42 
GeneralRe: Angular service error http 400 using .Net core api to accept json, escaped quotes crashing api Pin
jkirkerx30-Jun-20 6:06
professionaljkirkerx30-Jun-20 6:06 
Questionerror server Pin
Member 1265427722-Jun-20 2:37
Member 1265427722-Jun-20 2:37 
AnswerRe: error server Pin
ZurdoDev22-Jun-20 2:44
professionalZurdoDev22-Jun-20 2:44 
AnswerRe: error server Pin
Richard Deeming22-Jun-20 5:19
mveRichard Deeming22-Jun-20 5:19 
GeneralRe: error server Pin
Member 1265427722-Jun-20 23:37
Member 1265427722-Jun-20 23:37 
AnswerRe: error server Pin
Member 1265427722-Jun-20 23:41
Member 1265427722-Jun-20 23:41 
AnswerRe: error server Pin
OriginalGriff22-Jun-20 23:51
mveOriginalGriff22-Jun-20 23:51 
Except ... The first bit of code doesn't call the second:
C#
public DataSet GetLs(string que)
       {
...
       }

C#
public JsonResult LstDepartement()
     {
         DataSet ds2 =Dt.GetLsts ("select * from Departement");
...
     }
GetLs and GetLsts are not the same method ...

And to be honest, doing SQL that way is a very poor idea.
The trouble is that it's prone to SQL Injection. Suppose you want to get departments that all use the same SalesCode - that's easy, add a WHERE clause that specifies the code:
C#
DataSet ds2 =Dt.GetLsts ("SELECT * FROM Departement WHERE SalesCode = " + salescCode);

But ... that's really dangerous!

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?

And your system has no way to add parameters to a command, because you don't create the command until you have built the command string!
I'd strongly suggest you scrap that code and "do it properly" instead.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!

GeneralRe: error server Pin
Member 1265427723-Jun-20 1:34
Member 1265427723-Jun-20 1:34 
AnswerRe: error server Pin
OriginalGriff22-Jun-20 23:43
mveOriginalGriff22-Jun-20 23:43 
QuestionAnother NetCore question Pin
pkfox31-May-20 4:58
professionalpkfox31-May-20 4:58 
AnswerRe: Another NetCore question Pin
Mycroft Holmes31-May-20 12:22
professionalMycroft Holmes31-May-20 12:22 
GeneralRe: Another NetCore question Pin
pkfox1-Jun-20 1:58
professionalpkfox1-Jun-20 1:58 
GeneralRe: Another NetCore question Pin
Mycroft Holmes1-Jun-20 12:44
professionalMycroft Holmes1-Jun-20 12:44 
AnswerRe: Another NetCore question Pin
Richard Deeming1-Jun-20 3:31
mveRichard Deeming1-Jun-20 3:31 
GeneralRe: Another NetCore question Pin
pkfox1-Jun-20 4:08
professionalpkfox1-Jun-20 4:08 
AnswerRe: Another NetCore question Pin
jkirkerx1-Jun-20 13:47
professionaljkirkerx1-Jun-20 13:47 
GeneralRe: Another NetCore question Pin
pkfox4-Jun-20 10:54
professionalpkfox4-Jun-20 10:54 
QuestionCheckboxList Styling Problem Pin
feelblue8730-May-20 6:14
feelblue8730-May-20 6:14 
QuestionNet Core API question Pin
pkfox22-May-20 5:28
professionalpkfox22-May-20 5:28 
AnswerRe: Net Core API question Pin
Richard Deeming22-May-20 5:56
mveRichard Deeming22-May-20 5:56 
GeneralRe: Net Core API question Pin
pkfox22-May-20 7:05
professionalpkfox22-May-20 7:05 
QuestionHow do I multiple group in Active Directory ? Pin
ugurarslanm19-May-20 4:58
ugurarslanm19-May-20 4:58 
QuestionHow to invoke POST method by adding [FromBody] attribute in Postman tool Pin
meeram3917-May-20 23:33
professionalmeeram3917-May-20 23:33 
AnswerRe: How to invoke POST method by adding [FromBody] attribute in Postman tool Pin
Richard Deeming18-May-20 1:12
mveRichard Deeming18-May-20 1:12 

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.