Click here to Skip to main content
15,895,142 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# WPF Seeds code for Login on AD Azure Pin
Richard MacCutchan27-Aug-19 1:19
mveRichard MacCutchan27-Aug-19 1:19 
QuestionIntercepting a Logoff Pin
ormonds23-Aug-19 12:07
ormonds23-Aug-19 12:07 
AnswerRe: Intercepting a Logoff Pin
OriginalGriff23-Aug-19 19:42
mveOriginalGriff23-Aug-19 19:42 
GeneralRe: Intercepting a Logoff Pin
ormonds27-Aug-19 2:50
ormonds27-Aug-19 2:50 
GeneralRe: Intercepting a Logoff Pin
Dave Kreskowiak27-Aug-19 5:09
mveDave Kreskowiak27-Aug-19 5:09 
GeneralRe: Intercepting a Logoff Pin
ormonds27-Aug-19 13:10
ormonds27-Aug-19 13:10 
QuestionHow to print crystal report directly to printer without previewing in c# Pin
remiki22-Aug-19 23:01
remiki22-Aug-19 23:01 
AnswerRe: How to print crystal report directly to printer without previewing in c# Pin
OriginalGriff22-Aug-19 23:25
mveOriginalGriff22-Aug-19 23:25 
A couple of things unrelated to your question:
1) Never use Convert methods on user input: users mistype, and Convert will throw an exception on errors. Always check user input using the TryParse method instead:
C#
void report()
   {
   int fact;
   if (!int.TryParse(textBox4.text, out fact))
      {
      ... report input problem to user ...
      return;
      }
   // fact now contains a valid integer.


2) 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...

3) 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?

OK, in this example it wouldn't cause a problem, but you need to check every single other access in your application - miss one, and you are at risk. It's a very,. very good idea to get into the habit or always using parameterized queries, even when you don't have to - that way future changes are safer.

4) SqlConnections, SqlCommands, and so forth are scarce resources: you should ensure that they are Disposed when you are finished with them - the best way is to just use a using block for each constructor - the object will be disposed automatically when it goes out of scope.

As far as your actual question goes, we can't help based on the code you show: it doesn't display the report at all, just set up some conditions for it to be displayed or printed. You need to look elsewhere in your code to find out exactly what happens from that point.
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: How to print crystal report directly to printer without previewing in c# Pin
remiki23-Aug-19 0:33
remiki23-Aug-19 0:33 
GeneralRe: How to print crystal report directly to printer without previewing in c# Pin
OriginalGriff23-Aug-19 0:42
mveOriginalGriff23-Aug-19 0:42 
AnswerRe: How to print crystal report directly to printer without previewing in c# Pin
remiki23-Aug-19 1:02
remiki23-Aug-19 1:02 
GeneralRe: How to print crystal report directly to printer without previewing in c# Pin
OriginalGriff23-Aug-19 1:10
mveOriginalGriff23-Aug-19 1:10 
GeneralRe: How to print crystal report directly to printer without previewing in c# Pin
remiki23-Aug-19 1:24
remiki23-Aug-19 1:24 
GeneralRe: How to print crystal report directly to printer without previewing in c# Pin
OriginalGriff23-Aug-19 1:34
mveOriginalGriff23-Aug-19 1:34 
GeneralRe: How to print crystal report directly to printer without previewing in c# Pin
remiki23-Aug-19 1:40
remiki23-Aug-19 1:40 
GeneralRe: How to print crystal report directly to printer without previewing in c# Pin
OriginalGriff23-Aug-19 1:56
mveOriginalGriff23-Aug-19 1:56 
GeneralRe: How to print crystal report directly to printer without previewing in c# Pin
remiki23-Aug-19 2:00
remiki23-Aug-19 2:00 
GeneralRe: How to print crystal report directly to printer without previewing in c# Pin
OriginalGriff23-Aug-19 2:21
mveOriginalGriff23-Aug-19 2:21 
GeneralRe: How to print crystal report directly to printer without previewing in c# Pin
remiki23-Aug-19 2:29
remiki23-Aug-19 2:29 
GeneralRe: How to print crystal report directly to printer without previewing in c# Pin
OriginalGriff23-Aug-19 2:40
mveOriginalGriff23-Aug-19 2:40 
GeneralRe: How to print crystal report directly to printer without previewing in c# Pin
Richard MacCutchan23-Aug-19 3:27
mveRichard MacCutchan23-Aug-19 3:27 
GeneralRe: How to print crystal report directly to printer without previewing in c# Pin
OriginalGriff23-Aug-19 3:33
mveOriginalGriff23-Aug-19 3:33 
GeneralRe: How to print crystal report directly to printer without previewing in c# Pin
remiki23-Aug-19 11:44
remiki23-Aug-19 11:44 
GeneralRe: How to print crystal report directly to printer without previewing in c# Pin
remiki23-Aug-19 1:53
remiki23-Aug-19 1:53 
GeneralRe: How to print crystal report directly to printer without previewing in c# Pin
RobF_8323-Aug-19 11:33
RobF_8323-Aug-19 11:33 

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.