I might point out, from a quick browse of your recent posts that the reason for the most recent down vote was most likely as a result of posting in a solved thread with a new question.

Generally, if you have a new and unique question it gets a new thread, if your question is "solved" by someone else's post's resolution then it gets no thread at all. Resurrecting someone else's solved thread to start your own question is generally looked down upon.

As mentioned above, however, if you didn't get reputation loss from it, it really doesn't affect you other than as a reminder that you perhaps didn't do something in the accepted way, which is kind of the point of the voting system around here last I checked :)

I threw this together to illustrate what I was trying to convey with my pseudocode before. Please note that the reason I used .ToLower() on my inputs is to ensure that all characters being compared are in the same case as upper and lower case characters count as different when doing a straight comparison. In order to get the same result with the second compared to first (instead of just first compared to second) simply add another pair of loops with the reverse order for the comparison and you're set.[CODE]static void Main(string[] args)
string unmatched = ""; // Define output string
string word1 = Console.ReadLine().ToLower(); // Read input of word 1
string word2 = Console.ReadLine().ToLower(); // Read input of word 2
char[] word1charArray = word1.ToCharArray(); // Convert word 1 into character array
char[] word2charArray = word2.ToCharArray(); // Convert word 2 into character array
bool match = false; // Matched character condition set

        for (int a = 0; a < word1charArray.Length; a++) // Iterate through characters in word 1 array
            for (int b = 0; b < word2charArray.Length; b++) // Iterate through characters in word 2 array
                if (word1charArray[a] == word2charArray[b]) // Check if current character in word 1 array matches current character in word 2 array and set flag if matched
                    match = true;
            if (match != true) // If no match through all characters in word 2 with current character in word 1 add word 1 character to output string
                unmatched += ...

It's not that it [B]cannot be done[/B] without stored procedures, it's more that it's not as secure to do so without stored procedures.

When dealing with login procedures it's safest to keep user and password variables from being passed around from place to place.

Using stored procedures keeps the entire process on the SQL server with no data being passed other than confirmation of valid or invalid results.


While I'm not about to go ahead and do your code for you I will do what I can to put you in the right direction.

Using the following method you should be able to determine the letters that are not repeated between the two.[LIST=1]
[]Input user selected words as character arrays
]Loop all characters in array 1
[]ForEach character in array 1 check each character in array 2 for equality
]if character from array 1 matches 0 characters in array 2 then append to string variable for output
[]as additional step you can loop all characters in array 2 and compare them to array 1 as well so that you get all characters from 2nd word that don't match first word as well
]output string with unmatched characters
[/LIST]Based on your original example "Computer Program" output for option 1 would be "Cute" output for option 2 would be "CutePga"

Well there's an option where you can pull the UN/PW from the DB based on a query which checks against the UN only and confirm the PW against the associated PW for the UN you pulled.

In doing this, even if the PW is incorrect you still verify that the UN exists.

However, if you're not careful with the coding then you've now pulled the PW into the code-behind as a variable which is potentially accessible.

What you [B]could do[/B] is have both functions as stored procedures on the SQL server however. Benefit of this is that the checks are all done on the SQL server and do not ever come across to the code-behind.

Basically... SP#1 = check if UN exists in SB
if SP#1 returns records == 1 then execute SP#2
SP#2 check if PW matches record for associated UN
if SP#2 returns records == 1 then execute login
else execute failedLogin

Dunno if that makes sense but hope it helps.

AngelicOne commented: good logic +1


For shame... I thought I'd trained you better in the art of posting questions :twisted:

No code examples, no real details of any sort. You're breakin' my heart here man!

I find myself curious what language(s) if any you used prior to learning C#.

The reason I ask this is because I notice that you don't use any braces with your if/else statements. While they 'technically' can be omitted (as is evident from the fact that your code works without them) I've found that people whose first language is C# usually use them like so:[CODE]if (number % 2 == 0)
type = "even";
type = "odd";
}[/CODE]Whereas people who started with a language such as python let the indents do the work for them mostly. The only reason this came up is that it can make it easier to sort the conditions relating to each state within the if/else structure and ensure that code is being placed/executed in the correct places. Potentially, if not careful, the statement:[CODE]else if (number % 2 == 0)
type = "even";
Console.WriteLine(type);[/CODE]Could be misinterpreted as having the writeline only occurring during the 'else if' portion.

Again, just a curiosity was all :)

Relating to your question, I would definitely have to agree with ddanbe about simplifying your statements. For a multiple possibility if/else there is a definite use for 'else if' but for something where there are only ever 2 possibilities a straight up if/else is enough.

The one thing that concerns me is that, based on your original code, you should never have an unassigned value as there is only even or odd if dealing with an integer and it ...

[QUOTE=Momerath;1336024][code]FileStream f = File.Open(@"D:\TestData.txt", FileMode.Create);
f.Close();[/code][/QUOTE]Momerath's method will do what you require if all you need is the file to be emptied.

Essentially what it accomplishes is that it will open the file in create mode which makes any existing file with the same name be deleted and replaced with the new file. Further, the code closes the stream without adding to the new file leaving you with an empty new file.

If, on the other hand, you require some of the details of the file to remain then you will need to first read the details into a variable, prune off the unnecessary bits, then create the new same-name file and insert the trimmed contents.

[QUOTE=ddanbe;1335879]Small addition:
In my country, the comma is the decimal separator.
In other counrtries it is the point.[/QUOTE]Good point :) My statement was more towards the way the program looks at it however.

[COLOR="Green"]Int = whole numeral = no denomination of decimal or comma[/COLOR]

Let me put it in a different perspective then.

Person A gives an example of their work and is stuck in a particular place where their code isn't working. They've tried a few alternatives and it's apparent that they have the right general idea but are making a mistake or just misunderstood how something worked.
Person B gives a working example showing how it corrects the problem Person A encountered and Person A sees the reasoning and the mistake and corrects their work

Person A posts a question asking for a handout of code because they haven't bothered to look into or try to solve the issue themselves. They show no effort in their work and show no understanding of the key concepts in coding.
Person B gives a handout with no serious explanation of the concepts behind it.
Person A takes the handout, uses it, completes their project but comes back a week later with the same question (or a variant) because they didn't learn anything.

Not saying 100% that this falls into either category, just stating the logic behind my earlier statement.

ddanbe has the nail on the head there.

You are parsing text into integers. Any value other than a whole number (no commas) will be unable to be parsed in such a way and will terminate the process.

As a note, comma notation for numerals is not a computational or mathematical representation but a visual addition that, in fact, is rarely in common use any longer. The system doesn't understand 120,000 but would understand 120000. You would need to go into much more depth with your parsing if you want it to be able to handle comma-notation in your input.

Just a brief note here in relation to answering threads.

Person A asks question
Person B gives general answer with conceptual method
Person C gives spoon-fed answer complete with code
Person D gives spoon-fed answer complete with code
Person A takes spoon-fed answers, doesn't bother to look into conceptual method or learn how it works and learns nothing

Just a thought is all :twisted: carry on.

ddanbe commented: Good remark. +7

Your issue seems to be related to the DataColumn and not the Global from what I'm reading of the error. Your error is contained within the following segment ... [COLOR="Red"]dc[1].ToString();[/COLOR] ... It reads to me that you are saying the following:[code=c]// Create DataSet ds from db.GetDataSet(Co)
ds = db.GetDataSet(Co);
// Create DataTable dt from the first table of ds
DataTable dt = ds.Tables[0];
// Change the definition of Co
Co = new Password('K', "").SetSql();
// Re-create the dataset ds with new definition
ds = db.GetDataSet(Co);
// Create DataRow dr from dt which has not been reinitialized since
// it's original values were pulled
DataRow dr = dt.Rows[0];
// Create DataColumn dc from dt which has not been reinitialized since
// it's original values were pulled
DataColumn dc = dt.Columns[0];

            // Cycle through the DataRows (you've only made one DataRow definition
            // which is the equivalent of row 0 of your table) within all rows of
            // the datatable
            foreach (DataRow row in dt.Rows)
                // Cycle through the DataColumns (you've only made one DataColumn
                // which is the equivalent of column 0 of your table) for the table
                // based on the dr DataRow
                foreach (DataColumn column in dr.Table.Columns)
                    // Change GlobalVar2 to equal array position "1" of dc (which =
                    // dt.Columns[0])
                    Global.GlobalVar2 = dc[1].ToString();
                    // Change GlobalVar3 to equal array position "1" of dc (which =
                    // dt.Columns[0])
                    Global.GlobalVar3 = dc[1].ToString();

[/code]To be quite honest... between the DataRow and DataColumn ...

My one question relates to the following segment:[CODE]if (ctrControl.Controls.Count > 0)
}[/CODE]I'm confused as to what you're attempting to achieve here. Essentially, if I'm reading it correctly... You're creating a foreach statement at the top of your code that will cycle through (presumeably) all the controls within your form. You're creating IF checks for each type of control to handle different requirements in 'clearing' them.

Now, if I read it right, you're then saying "If the current control has subcontrols, recursively call this same procedure on the subcontrols."

I can see how this might cause a bit of an issue, particularly as you're creating a loop within a loop and utilizing the same variables for both loops which also act as controlling variables on both loops.

As indicated by rohand, however, it would be much easier to pinpoint specific issues in the code if the actual error was provided from the debugger for us to see :)

Ok... I may be missing something here but...

Nowhere in the code you provided does the term 'nvarchar' exist.

So either the issue is not with the portion you provided (ie: in code-behind or in a stored procedure on the DB end) or the error is being relayed incorrectly by you to us :)

Just above the box where you post replies you should see the link to 'solve' the thread.

[QUOTE=Ryshad;1326497]You'll need to fix the following as well as implementing your search:

[CODE]DateTime search1 = new DateTime();
string s = search1.ToString(Console.ReadLine());[/CODE]I'll rephrase that..you ought ot fix it. Apparently the output is correct, but it is not the intended use of the method and may have unexpected results down the line.[/QUOTE]Actually, I'm surprised I missed that myself.

Realistically, unless he's converting the info in the text file to dateTime format for local variable comparison, the dateTime portion doesn't need to exist at all and can entirely be handled by strings. The only place where he would need dateTime is if he was working with a webform or windows form where the inputs would possibly be coming from a date/time picker. In console it's all text and can be done entirely with strings.

I just hope it was more helpful the way I put it the 2nd time (and that I didn't botch the loop/condition)... it took me the length of 2 replies and 1 edit to your first reply to type it all out lol.

OK... I'll try again...

You used:[CODE] Console.WriteLine("Enter the date in format {dd/mm/yyyy} :: ");
date = DateTime.Parse(Console.ReadLine());
sw.WriteLine("Date :: "+date); // User Input Date

        Console.WriteLine("Enter the name of the person you want to meet :: ");
        name = Console.ReadLine();
        sw.WriteLine("Name of the person :: "+name); // User Input Name

        Console.WriteLine("Enter the your visit time in format {HH:MM:SS} :: ");
        time = DateTime.Parse(Console.ReadLine());
        sw.WriteLine("Visit time :: "+time); // User Input Time
        sw.Close();[/CODE]Now, personally... Where you have the following:[CODE]        public void search()
        string fName = @"C:\Data.txt ";
        StreamReader testTxt = new StreamReader(fName);
        string allRead = testTxt.ReadToEnd();

        Console.WriteLine("Enter the date in format {dd/mm/yyyy} :: ");
        DateTime search1 = new DateTime(); 
        string s =  search1.ToString(Console.ReadLine());

        if (allRead.Contains(s))

            Console.WriteLine("not found");

    }[/CODE]I would do the following instead:[CODE]        public void search()
        string fName = @"C:\Data.txt ";
        StreamReader testTxt = new StreamReader(fName);
        // string allRead = testTxt.ReadToEnd();

        Console.WriteLine("Enter the date in format {dd/mm/yyyy} :: ");
        DateTime search1 = new DateTime(); 
        string s =  search1.ToString(Console.ReadLine());
        r2 = testTxt.ReadLine()
        bool found = false;
        while (r2 != null && found == false)
            if (r2.Contains(s))
                string tmpRead = "";
                Console.WriteLine("{0}", r2); // Print Date Found
                tmpRead = testTxt.ReadLine(); // Read Next Line and Print Name
                Console.WriteLine("{0}", tmpRead);
                tmpRead = testTxt.ReadLine(); // Read Next Line and Print Time
                Console.WriteLine("{0}", tmpRead);
                found == true
            Console.WriteLine("not found");


[/CODE]The only drawback to this method being that it will display the first record for a given ...

Rather than go into great detail in providing the answer here I'll let others who've provided the answer in the past do my talking for me :twisted:

Below is a code snippet (recommended read for this topic) and a couple of related threads that may help you out:

[URL="http://www.daniweb.com/code/snippet298708.html"]Snippet[/URL] (Thanks [URL="http://www.daniweb.com/forums/member588414.html"]Ryshad[/URL])
[URL="http://www.daniweb.com/forums/post1300247.html#post1300247"]Link[/URL] containing links to other threads that will help

Hope these help solve your issue :) Please remember to mark your thread solved once the issue is resolved. Also, if these don't solve your issue, please provide more info as to what the problem is so we can be more specific with our help.

[COLOR="Green"]EDIT: Passing info between layers is [B]similar to[/B] passing between forms. Please note the main part of the above snippet/links being that an 'instance' of each layer needs to exist in order to reference components between them.[/COLOR]

Well you know how many lines the input should be (3 if I read it properly):[LIST=1]

If I were you I would take the line with the found date and the following 2 lines and input them into 3 corresponding variables.

[]Found Date on Line 4
]Line 4 input into fDate variable
[]Line 5 input into fName variable
]Line 6 input into fTime variable
[/LIST]Those would be the steps, the coding shouldn't be too much of a stretch from there :twisted:

Hope that helps, please remember to mark the thread solved once your issue is resolved.

Unless you're planning for there to be a vast number of users logging in simultaneously you should be fine with the server-side solution. You might just want to ensure there are the least possible number of server-calls for the confirmation that you need (ie: once per page instead of once per function that requires login creds).

Hope that helped at least :) Please remember to mark your thread solved once the issue is resolved.

Perhaps I wasn't 'clear' enough with my answer then :P

From what you had said:

My question is, should I be storing this information in a http cookie instead of a variable?

And you had indicated one of the concerns was overall processing requirements compared to your variable approach.

My answer basically was to give an overview of the pros/cons of cookie usage for this sort of thing...

Essentially, cookie:[LIST]
[]user-end = less 'server end' processing
[]Can be disallowed by the browser negating effectiveness
[/LIST]Server-side user login based variable:[LIST]
]Server-end (obviously)
[]Invisible to the user
]Not affected by browser settings
[/LIST]Beyond that, the choice is yours... If it's being checked against frequently then the cookie method may be better as it doesn't require additional calls to the server to check the bool setting. If it's being checked against infrequently or security is of concern then the server-side bool is better.

[COLOR="Green"]Alternately, if you need to use the server-side (hidden from user, better 'security' of information) you can always restrict the call to the beginning and end of the 'login session' and simply pass the value forward from page to page. The problem there is you would need some sort of if/else in place on each page where it checks to see if the value was passed locally from another calling page and if it doesn't find it, it then goes to the server to check there. (dunno if that makes much sense but I couldn't think of a better ...

Another variation on what Ryshad indicated is to simply use the [URL="http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.split.aspx"]Regex.Split[/URL] method which works the same as the single character split but allows string definition for the split markers.

This can be done by first defining a regex pattern then using that pattern in your split command as such:[CODE]Regex reg = new Regex(@"><");
string[] sections = Regex.Split(inputString, reg);[/CODE]Or it can be used in the following way:[CODE]string[] sections = Regex.Split(inputString, @"><");[/CODE]That is, of course, unless my brain has completely rotted and I've forgotten how to use Regex already :twisted:

Hope this helps :) I know the thread's a few days old but it's still 'unsolved' so figured maybe more info could be useful.

There are pros and cons to using a cookie to store login variables for a website.

[]Cookies can be set to terminate either at end of session or after a specified time period
]Cookies are relatively easy to write/read
[]Cookies are client side and don't require much server overhead
]Cookies can be read easily and possibly 'impersonated'
[]Cookies can be easily mis-coded
]Many people disallow cookies on their browsers
[/LIST]There are other factors to consider but my purpose is just to give an overview of cookies' usefulness.

If you utilize non-descript variables in the cookies (such that it's not apparent that it's a login credential) you should be relatively ok using them for this purpose. Keep in mind that unless otherwise coded, cookies self-terminate as soon as [B]all browser windows are closed[/B] (ie: browser 'session' ends).

Generally, for the purpose you've described, cookies will likely be the best bet as they are one of the few persistent methods of session state control available. Your only major drawback is that it obviously won't work if the user doesn't allow cookies on their machine.

The livejournal "icon" that you're referring to is commonly known as a '[URL="http://www.w3.org/2005/10/howto-favicon"]favicon[/URL]' and is generated from an icon file in your web directory (or an image directory which is referenced by the metatag(s) for the favicon in your webpage(s)).

If you click the link I provided above you will see a 'how to' related to favicons that might help you sort out:[LIST=1]
[]Where your current favicon is located
]How to create a custom favicon for your site
[/LIST]Hope that helps :) Please remember to mark your thread solved once your issue is resolved.

Realistically... if you had the resolution of the screen and the actual monitor dimensions (inside dimensions vertical and horizontal) then you could do a straight ratio conversion.

For example, my resolution is 1680x1050 but I don't have an actual measuring tape handy to tell you the height and width of the "viewable space" of my screen. It's claimed to be a 22" 16:9 ratio screen though so some mathematics would be able to get you there.

The thing is, if you ask just for the "monitor size" that doesn't take into account the variables of whether it's standard size, wide screen, ultra-wide screen... You'd need to at the very least know the 'size', ratio and resolution setting to be accurate in this.

Dunno if that helps or just confuses the issue further :)

I'd recommend that you check out the following [URL="http://www.google.com/#hl=en&q=text+append+io+site%3Amsdn.microsoft.com"]search[/URL] for many links related to the process you're looking for :twisted:

What you're looking for is the Append file access mode which opens an existing file for writing but places new content at the end of the file instead of overwriting from the beginning. For this you can use the standard filestream method of accessing the file and utilize the [URL="http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx"]append access mode[/URL] or you can use the [URL="http://msdn.microsoft.com/en-us/library/system.io.file.appendtext.aspx"]File.AppendText[/URL] method depending on your needs.

Hope this helps :)

Geekitygeek commented: google == friend :D +3

new_SE Could you please be a bit more specific about what it is you're trying to do here? Your post is far from clear and therefor difficult to answer.

[QUOTE=jbisono;1308344]Try to calculate that at the database level, and return the total with your result. your statement should looks like
[/code][/QUOTE]Definitely agree with bisono here that your best bet is to sum the totals at the SQL server end and return the value directly. Not only does this cut down on overhead in your local code but it also provides the 'total' results as part of the returned dataset so they are directly 'related' to the other values you are retrieving and easily retrieved on a line by line basis. This is preferable to performing the calculation after the fact on the code-behind or front-end levels as it 'ties' the results to the source more directly (read: less chance for information mismatch).