Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
Questionwhy the data been sent out after socket.close(), not socket.send(). Pin
viming4-Jul-23 16:06
viming4-Jul-23 16:06 
AnswerRe: why the data been sent out after socket.close(), not socket.send(). Pin
OriginalGriff4-Jul-23 18:19
mveOriginalGriff4-Jul-23 18:19 
GeneralRe: why the data been sent out after socket.close(), not socket.send(). Pin
viming4-Jul-23 21:05
viming4-Jul-23 21:05 
GeneralRe: why the data been sent out after socket.close(), not socket.send(). Pin
OriginalGriff4-Jul-23 21:14
mveOriginalGriff4-Jul-23 21:14 
AnswerRe: why the data been sent out after socket.close(), not socket.send(). Pin
jschell5-Jul-23 5:26
jschell5-Jul-23 5:26 
QuestionProblem with string array? Pin
Member 140558794-Jul-23 6:28
Member 140558794-Jul-23 6:28 
AnswerRe: Problem with string array? Pin
Dave Kreskowiak4-Jul-23 7:06
mveDave Kreskowiak4-Jul-23 7:06 
AnswerRe: Problem with string array? Pin
OriginalGriff4-Jul-23 18:21
mveOriginalGriff4-Jul-23 18:21 
A couple of things:

1) This is one of the most common problems we get asked, and it's also the one we are least equipped to answer, but you are most equipped to answer yourself.

Let me just explain what the error means: You have tried to use a variable, property, or a method return value but it contains null - which means that there is no instance of a class in the variable.
It's a bit like a pocket: you have a pocket in your shirt, which you use to hold a pen. If you reach into the pocket and find there isn't a pen there, you can't sign your name on a piece of paper - and you will get very funny looks if you try! The empty pocket is giving you a null value (no pen here!) so you can't do anything that you would normally do once you retrieved your pen. Why is it empty? That's the question - it may be that you forgot to pick up your pen when you left the house this morning, or possibly you left the pen in the pocket of yesterday's shirt when you took it off last night.

We can't tell, because we weren't there, and even more importantly, we can't even see your shirt, much less what is in the pocket!

Back to computers, and you have done the same thing, somehow - and we can't see your code, much less run it and find out what contains null when it shouldn't.
But you can - and Visual Studio will help you here. Run your program in the debugger and when it fails, it will show you the line it found the problem on. You can then start looking at the various parts of it to see what value is null and start looking back through your code to find out why. So put a breakpoint at the beginning of the method containing the error line, and run your program from the start again. This time, the debugger will stop before the error, and let you examine what is going on by stepping through the code looking at your values.

But we can't do that - we don't have your code, we don't know how to use it if we did have it, we don't have your data. So try it - and see how much information you can find out!

2) 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?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!

GeneralRe: Problem with string array? Pin
jschell5-Jul-23 5:28
jschell5-Jul-23 5:28 
QuestionPredicateBuilder Question Pin
Kevin Marois30-Jun-23 8:54
professionalKevin Marois30-Jun-23 8:54 
AnswerRe: PredicateBuilder Question Pin
Dave Kreskowiak1-Jul-23 4:23
mveDave Kreskowiak1-Jul-23 4:23 
GeneralRe: PredicateBuilder Question Pin
Kevin Marois1-Jul-23 8:21
professionalKevin Marois1-Jul-23 8:21 
AnswerRe: PredicateBuilder Question Pin
BillWoodruff1-Jul-23 9:54
professionalBillWoodruff1-Jul-23 9:54 
AnswerRe: PredicateBuilder Question Pin
James Curran5-Jul-23 10:41
James Curran5-Jul-23 10:41 
QuestionUnable to Receive data from Cobas e411 Serial Port Pin
Member 1493027227-Jun-23 22:20
Member 1493027227-Jun-23 22:20 
AnswerRe: Unable to Receive data from Cobas e411 Serial Port Pin
Richard MacCutchan27-Jun-23 23:08
mveRichard MacCutchan27-Jun-23 23:08 
AnswerRe: Unable to Receive data from Cobas e411 Serial Port Pin
OriginalGriff27-Jun-23 23:38
mveOriginalGriff27-Jun-23 23:38 
AnswerRe: Unable to Receive data from Cobas e411 Serial Port Pin
Ralf Meier28-Jun-23 0:43
mveRalf Meier28-Jun-23 0:43 
AnswerRe: Unable to Receive data from Cobas e411 Serial Port Pin
jschell28-Jun-23 6:08
jschell28-Jun-23 6:08 
GeneralRe: Unable to Receive data from Cobas e411 Serial Port Pin
Member 1493027228-Jun-23 6:21
Member 1493027228-Jun-23 6:21 
AnswerRe: Unable to Receive data from Cobas e411 Serial Port Pin
Gerry Schmitz28-Jun-23 6:51
mveGerry Schmitz28-Jun-23 6:51 
QuestionGoogle PeopleAPI & HttpListener Redirect URI Pin
Kevin Marois22-Jun-23 10:03
professionalKevin Marois22-Jun-23 10:03 
AnswerRe: Google PeopleAPI & HttpListener Redirect URI Pin
jschell23-Jun-23 10:45
jschell23-Jun-23 10:45 
GeneralRe: Google PeopleAPI & HttpListener Redirect URI Pin
Kevin Marois23-Jun-23 12:18
professionalKevin Marois23-Jun-23 12:18 
GeneralRe: Google PeopleAPI & HttpListener Redirect URI Pin
Richard Andrew x6425-Jun-23 11:44
professionalRichard Andrew x6425-Jun-23 11:44 

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.