Click here to Skip to main content
15,879,019 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# - showing pdf files from mySQL database without using acrobat reader, how? Pin
sameer54925-Feb-18 22:14
sameer54925-Feb-18 22:14 
AnswerRe: C# - showing pdf files from mySQL database without using acrobat reader, how? Pin
Eddy Vluggen26-Feb-18 0:10
professionalEddy Vluggen26-Feb-18 0:10 
QuestionMessage Removed Pin
23-Feb-18 9:25
Member 1369343023-Feb-18 9:25 
QuestionMemory leak when converting Bitmap to BitmapImage Pin
Leif Simon Goodwin21-Feb-18 23:55
Leif Simon Goodwin21-Feb-18 23:55 
QuestionC# - How to find total rows affected when using EventLogReader (eventLogQuery)? Pin
Shanmuga Sundaram21-Feb-18 19:56
Shanmuga Sundaram21-Feb-18 19:56 
AnswerRe: C# - How to find total rows affected when using EventLogReader (eventLogQuery)? Pin
Gerry Schmitz22-Feb-18 11:53
mveGerry Schmitz22-Feb-18 11:53 
GeneralRe: C# - How to find total rows affected when using EventLogReader (eventLogQuery)? Pin
Shanmuga Sundaram22-Feb-18 19:22
Shanmuga Sundaram22-Feb-18 19:22 
QuestionIs it ok NOT to pass fields into the methods in the same class as parameters? Pin
User9874320-Feb-18 8:59
professionalUser9874320-Feb-18 8:59 
In the following snippet of a class, I'm passing a reference to connection_string (a private field in the same class) into ExecuteScalar method by way of the connection_string parameter.

But in SomeMethod, I'm using connection_string, even though I haven't passed it into the method as a parameter.

Which way is the most common and why?
		class public DBCall
{
private string connection_string = "...";

private void SomeMethod()
{
     var zipcode = ExecuteScalar<string>("select zipcode from ZIpcodes where Zip='92108'", connection_string);

}

public T ExecuteScalar<T>(string queryString, string connection_string)
		{
			using (OleDbConnection conn = new OleDbConnection (connection_string))
			{
				using (OleDbCommand cmd = new OleDbCommand (queryString , conn))
				{
					var result = cmd.ExecuteScalar ( );

					if (Convert.IsDBNull (result) && typeof (T).IsValueType)
						return default (T);                                         // if the db value is null, but T is a value type, set T = the default value of the type.
					else
						return (T) (result);
				}
			}
		}

		private void treeView1_NodeMouseClick(object sender , TreeNodeMouseClickEventArgs e)
		{

			if (e.Button == MouseButtons.Left)
			{
				string loadrowset = e.Node.Text;
				Rowset rowset = (Rowset) Enum.Parse (typeof (Rowset) , loadrowset);
				using (OleDbConnection conn = new OleDbConnection (ConnectionString))
				{
					OleDbSchemaTable s = new OleDbSchemaTable (rowset , conn);

					DataTable dt = new DataTable ( );
					dt = s.datatable;

					dataGridView1.Enabled = true;
					dataGridView1.DataSource = dt;	
				}

			}
			else
			{
				return;
			}

		}

The lack of surety in programming is part of the reason software is fragile.

AnswerRe: Is it ok NOT to pass fields into the methods in the same class as parameters? Pin
Richard MacCutchan20-Feb-18 9:05
mveRichard MacCutchan20-Feb-18 9:05 
GeneralRe: Is it ok NOT to pass fields into the methods in the same class as parameters? Pin
User9874320-Feb-18 9:35
professionalUser9874320-Feb-18 9:35 
GeneralRe: Is it ok NOT to pass fields into the methods in the same class as parameters? Pin
Richard MacCutchan20-Feb-18 9:48
mveRichard MacCutchan20-Feb-18 9:48 
SuggestionRe: Is it ok NOT to pass fields into the methods in the same class as parameters? Pin
Richard Deeming20-Feb-18 10:00
mveRichard Deeming20-Feb-18 10:00 
GeneralRe: Is it ok NOT to pass fields into the methods in the same class as parameters? Pin
User9874316-Mar-18 2:50
professionalUser9874316-Mar-18 2:50 
AnswerRe: Is it ok NOT to pass fields into the methods in the same class as parameters? Pin
Bernhard Hiller20-Feb-18 23:26
Bernhard Hiller20-Feb-18 23:26 
GeneralRe: Is it ok NOT to pass fields into the methods in the same class as parameters? Pin
User9874316-Mar-18 2:59
professionalUser9874316-Mar-18 2:59 
AnswerRe: Is it ok NOT to pass fields into the methods in the same class as parameters? Pin
Eddy Vluggen21-Feb-18 3:03
professionalEddy Vluggen21-Feb-18 3:03 
GeneralRe: Is it ok NOT to pass fields into the methods in the same class as parameters? Pin
User9874316-Mar-18 3:01
professionalUser9874316-Mar-18 3:01 
GeneralRe: Is it ok NOT to pass fields into the methods in the same class as parameters? Pin
Eddy Vluggen16-Mar-18 7:13
professionalEddy Vluggen16-Mar-18 7:13 
AnswerRe: Is it ok NOT to pass fields into the methods in the same class as parameters? Pin
V.21-Feb-18 21:26
professionalV.21-Feb-18 21:26 
GeneralRe: Is it ok NOT to pass fields into the methods in the same class as parameters? Pin
User9874316-Mar-18 3:03
professionalUser9874316-Mar-18 3:03 
GeneralRe: Is it ok NOT to pass fields into the methods in the same class as parameters? Pin
V.16-Mar-18 3:42
professionalV.16-Mar-18 3:42 
Questionan interesting aspect of C# 7 extended Tuple semantics Pin
BillWoodruff20-Feb-18 2:11
professionalBillWoodruff20-Feb-18 2:11 
AnswerRe: an interesting aspect of C# 7 extended Tuple semantics Pin
Richard Deeming20-Feb-18 2:32
mveRichard Deeming20-Feb-18 2:32 
GeneralRe: an interesting aspect of C# 7 extended Tuple semantics Pin
BillWoodruff20-Feb-18 4:23
professionalBillWoodruff20-Feb-18 4:23 
GeneralRe: an interesting aspect of C# 7 extended Tuple semantics Pin
Richard Deeming20-Feb-18 4:29
mveRichard Deeming20-Feb-18 4:29 

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.