|
yes, now that you've fixed it, it should show up as the value you passed. Your question was why did it allow this in the first place? Your original post stated "It populates the field with an empty string instead of the value". That was my question was the value showing up in the db as any empty string or null, before you fixed it? There is a difference. I think your application was posting an empty string and not a null value, thus passing the db's test to not allow nulls. and since you do not have the field set as auto-incrementing an empty string would be a valid unique string. You probably could not run it twice in a row since that would violate the "unique" requirements of a pk. I guess in any event it is working now, eh?
-Kevin
|
|
|
|
|
Yes, it is working. Your analysis is correct. It put an empty string it orig. and not the value.
Thanks for your help!
|
|
|
|
|
Elina, Thank you so much, that was the issue!!
|
|
|
|
|
I have a few questions over speed and threading of the .NET 2.0 web browser control...
1) Which of the following is the "faster" methodology for capturing events HTML events?
a) setting up custom scripting methods (window.external with an ObjectForScripting and ScriptMethods)
b) nabbing HTML elements and setting events to them (.GetElementById() and then adding an event to it)
To me it seems that the more diversity as it can be called from any object by evoking the window.external script object, but if nabbing HTML elements is "quicker" by only monitoring one element instead of waiting on a method call it might be best.?.
2) Also do you think it'll be safe to interact with the web browser control cross thread? or should I make some type of external method in the owner class to interact with the web browser control to be called from the 2nd thread?
(I think I should do the later, but it might not be safe at all.?.)
|
|
|
|
|
I want to move focus to next cell by click on Enter button. I am using DataGridView control ,how?
-- modified at 13:10 Monday 10th September, 2007
welcome in hims.
|
|
|
|
|
hi friend's
i have a method that do below code:
for(int i=0;i<=max;i++)
str+=i.ToString();
i want to create two thread that call this method at a same time.
but i have a problem:
max and str are variables that difference for each thread it means that each thrad must have max and str that contain a difference value from other threads.
what i have to do?
thank you for your guide.
nobody help you...
you have to help you yourself
and this is success way.
|
|
|
|
|
Then don't make them static.
|
|
|
|
|
Hi,
don't use statics for things that are not unique at all. Instead:
make a class that contains some data (str, max) and a method containing your for loop.
have its constructor create a thread calling that method. Now instantiate two objects.
BTW: you did not specify any output, so I will assume the method ends on
Console.WriteLine(str); .
Otherwise you may need some delegate to report results to the original class.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi all,
Anyone know how to see the actual xml-document sent by HttpWebRequest when using webservices?
Thanks,
smsmfe
|
|
|
|
|
smsmfe wrote: Anyone know how to see the actual xml-document sent by HttpWebRequest when using webservices?
I have no idea how to do that but if I needed to I would start here[^]
|
|
|
|
|
Hi people
I have an idea for an algorithm, but am gonna need some help in actually implementing it.
What I need to do is read file paths from right to left, comparing all of them, finding the right-most unvarying element of the path.
An example of how I want this algorithm to work is below
C:\Root Dir\Const Sub Dir1\Sub Dir1
C:\Root Dir\Const Sub Dir1\Sub Dir2
C:\Root Dir\Const Sub Dir1
Path scanned was C:\Root Dir\Const Sub Dir1
Any ideas would be greatly appreciated
Cheers
Give me strength, give me caffeine
|
|
|
|
|
How about something like this: split the string into pieces separated by the \ character. You can do this using theString.Split('\\')
Once you've split the string up into an array, you can check the last elements of the array for the differences.
|
|
|
|
|
It will actually be faster to just go left to right, comparing each char as you go. When one of the chars varies, return the current string (as follows):
List<string> paths = new List<string>();
int shortestPathLength;
// Populate paths and shortestPathLength
if (paths.Count == 0) return string.Empty;
string result = string.Empty;
string tempResult = string.Empty;
for (int charIdx = 0; charIdx < shortestPathLength; ++charIdx) {
char c = paths[0][charIdx];
for (int pathIdx = 1; pathIdx < paths.Length; ++pathIdx) {
if (paths[pathIdx][charIdx] != c)
return result;
}
// Not sure if "DirectorySeparator" is the property, but you get the idea
if (c == Path.DirectorySeparator)
result = tempResult;
tempResult += c.ToString();
}
return tempResult;
Hope this helps!
Jeff
|
|
|
|
|
Cheers Jeff
Yeah this helped, am now working on translating your example into my source code, gonna be a long old scan, considering am talking about 3500+ paths here
Sam
Give me strength, give me caffeine
|
|
|
|
|
If you are dealing with that many paths, you could skip the first three characters if you know for sure they all start on the C drive. If not, you could skip only the second and third characters since you know they will be ":\" for all paths. Other than this optimization, there is no way to improve the efficiency of this algorithm since every character will need to be compared to check for equality.
Jeff
|
|
|
|
|
Tip:
Instead of creating a lot of intermediate strings by adding one character at a time, make result an int, put the length of tempResult in result, and use tempResult.Substring(0, result) to get the string.
---
single minded; short sighted; long gone;
|
|
|
|
|
Good call! In fact, you could change the code to be the following for max optimization using the previous suggestions:
int result = 0;
for (int charIdx = 0; charIdx < shortestPathLength; ++charIdx) {
if (charIdx == 1) {
++charIdx;
result = 2;
continue; // Skip the :\ from the path
}
char c = paths[0][charIdx];
for (int pathIdx = 1; pathIdx < paths.Length; ++pathIdx) {
if (paths[pathIdx][charIdx] != c)
return paths[0].Substring(0, result);
}
// Not sure if "DirectorySeparator" is the property, but you get the idea
if (c == Path.DirectorySeparator)
result = charIdx;
}
return paths[0].Substring(0, shortestPathLength);
|
|
|
|
|
Hi,
there is a lot of opportunity for optimizations here;
I assume you are not interested in partial folder names (i.e. C:\A\B1 and C:\A\B2 have
C:\A in common, not C:\A\B).
The candidate result initially equals the first string.
The only thing that can happen to it is you must drop everything from the last backslash
up to the end (possibly performed iteratively).
Something like:
public string findCommonPath(string[] strings) {
string common=strings[strings.Length-1];
foreach(string str in strings) {
while (!str.StartsWith(common)) {
int i=common.LastIndefOf(@"\");
if (i<=0) return null;
common=common.SubString(0,i);
}
}
return common;
}
remarks:
- you may want to do everything in case-insensitive way;
- if your strings happen to be sorted alphabetically, you should only compare the first
and last one !
- I started with the last string hoping it differs most from the first one, resulting
in a sooner shortening of common, hence less CPU cycles for StartsWith.
- if you happen to know what the shortest string is, you may want to handle that one first.
- the number of objects created is very low (in the order of the number of backslashes
in the first string)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I don't think that this algorithm will be faster in most cases. Here is why I think so:
1. The StartsWith will compare at most the length of common, but at least as much as the length of the match
2. LastIndexOf will compare the difference between the current guess at the common string and the next guess at the common string
3. Taking the substring will require the length of common to copy.
So the only time that I can think of where this algorithm would save time would be if you have two non-matching directories that start identically, such as "Food for thought" and "Food for thomas", and those are the ONLY directories you are comparing. Assuming that this is not the case (typical, since there are thousands of entries), the other way cuts out the expenses from parts 2 and 3. The other issue that I see with this is that if you have 3500 paths, and the first 200 fall into a directory that is NOT going to end up as the common directory, you spend a lot of extra time being told that these directories in fact do match a directory that doesn't matter. I also think that directory names in windows are case-sensitive, so the suggestion on making the comparison case-insensitive is unnecessary and takes more time (since you have to then convert the chars to lowercase). One thing that I do like is the suggestion to compare the first and last if they are already sorted (doubtful since you don't already know the common directory). The assumption made as to the efficiency of this algorithm also depends on the collection being "roughly" sorted, that is that the first and last directories differ significantly, which will reduce the amount of time wasted on using "StartsWith". Anyway, those are the reasons that I would stick with the other algorithm myself.
Jeff
|
|
|
|
|
There are many reasons why the character-based approach will not perform as well as one
would hope, including character indexing cost, cache inefficiency, etc. My approach makes
use of StartsWith which I assume is highly optimized, traverses the string collection only
once and for each string uses all the characters at once, drastically increasing the
level 1 cache efficiency.
If you really want to know, implement both and run some relevant tests.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Cache efficiency almost certainly gets better with this method. I am interested in the result of timing the two algorithms if c#_keithy takes the time to do it. If so, let us know which performs better on your data and maybe any noticable tendencies in the dataset you used.
Jeff
|
|
|
|
|
Cheers everyone, your input was greatly appreciated, the algorithm was needed to find the path that was recursively scanned to populate the database with file content information.
Am still working on an implementation of the algorithm using alphabetic sorting and comparing the top and bottom records, using a for loop
For now I am just storing meta data on the database so that I can automatically tell what path was scanned
Give me strength, give me caffeine
|
|
|
|
|
I would like to display a password in a DataGridViewTextBoxColumn. I want the password to be shown as characters ie. *. How can I achieve this?
|
|
|
|
|
there are more technics to solve ur problem:
and this is on of them:
u can add the temprory field to your gridview and then on it add a textbox with special name such as pass then put your favorite info from your db (for example...).
now you must to write below code in the rowcommand event of your gridview:
object obj=gridview.rows[index rows].findcontroll("pass");
textbox txt=(textbox)obj;
and in this step you must to write your favorite character instead of the real password.
txt is a object that contain information of the pass word for each rows that seperate by index rows.
good luck
nobody help you...
you have to help you yourself
and this is success way.
|
|
|
|
|
Hi all
I have created a window service which just starts a thread on its start method.it was working fine.Now when i stopped the service and just restart the service without any changes i am getting an error
"could not restart the service
The service didnot respond to the start or control request in a timely fashion"
Why is it so.Can any one pls help me
Thanks in advance
Regards
DilipRam
|
|
|
|