|
Indeed, but that's for a separate issue (i.e. it's quicker to check the length). The fuller check is to use string.IsNullOrEmpty to check because the value might be null or it might be empty, in which case value.Length would throw an ArgumentNullException .
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Pete O'Hanlon wrote: string.Empty doesn't change the value of the string unless you assign
You are absolutely right, and I grovel, lots. I can only blame complete and utter brain failure, brought on by unexpected sunshine.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Ok wait, what are you trying to achieve? This code (even if I pretend that the == works) does not do anything useful.
Suppose view is null: NullReferenceException
Or the value returned by GetFocusedValue is null: NullReferenceException
Or the value returned by ToString is null: strSequence is null
ToString returns "": strSequence is ""
ToString returns anything else: strSequence is ""
So you either get an exception, or you get a useless value in strSequence. What's the deal here? What did you want to do?
If what you want is: the value of view.GetFocusedValue().ToString() if it isn't null, or "" if it is null
Then you could do:
string strSequence = view.GetFocusedValue().ToString() ?? "";
Disclaimer: I just woke up, it's entirely possible that I'm not making any sense at all - sorry!
|
|
|
|
|
Harold, Thanks for that - I think that is exactly what I need. Basically all I want to do is check if View.GetFocusedValue... is null. If it is null then assign a "" otherwise use the View.GetFocusedValue. What will happen with it if the value comming back happens to be DBNull.Value (assuming I was doing something with a dataset.
Thanks
|
|
|
|
|
With the code I suggested you could still get a nasty NullRef, but how about
var FocusVal = view.GetFocusedValue();
string strSequence = "";
if (FocusVal != null)
strSequence = FocusVal.ToString();
Alternatively:
string strSequence = (view.GetFocusedValue() != null) ? view.GetFocusedValue().ToString() : "";
Would call GetFocusedValue twice though so only use if that's ok.
Or if GetFocusedValue returns a string:
string strSequence = view.GetFocusValue() ?? "";
edit: oh I missed the DBNull thing, well that might change things in ways unknown to me - I've never used database code..
|
|
|
|
|
Hello Experts
i am facing one problem regarding data source of crystal report.when i switched to another server then data source location cant change automatically,i have to update it.
tel me solution for this.i.e.when server changes data source location also changed.
|
|
|
|
|
KIDYA wrote: tel me solution
Call Crystal, it is there problem!
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Didnt get what r u trying to say?Be specified.
|
|
|
|
|
Engage your cranium.
This has nothing to do with C# and everything to do with Crystal Reports.
Ask them, not us!
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
I have to read a file, search for a special character 'ç', its ascii equivalent is 0231 (c-cedilla) and replace it with a space. I have tried File class's ReadAllBytes / ReadAllText / ReadAllLines with Encoding.ASCII to read the file, but when it comes to this special character, it reads as '?' whose ascii equivalent is 63.
How to do this?
Any kind of help will be appreciated.
Thanks in advance
harry
|
|
|
|
|
the file format is probably unicode. just find the byte, then replace it with "space"-byte.
|
|
|
|
|
maybe/maybe not. The file format is probably ascii, just not in the right codepage. Unicode should not have any problem.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
how to find the exact byte and replace it. is there any class / method available in c# 2.0?
|
|
|
|
|
You are opening the file as a text file and so the codepaging is going through and saying 'bad c-cedilla, we no know you' and baneshes it to the wind.
Try opening the file as data and searching the bytes for the cedilla and blapping it.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
how to do this, i mean which class i can use to open the file as data and then look for the specific byte for cedilla?
please help, thanks
|
|
|
|
|
The FIRST class in System.IO is BinaryReader . Guess what it does?
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
i think diffrent encoding make this problem
to solve this problem without any knowledge about encoding use System.IO.StreamReader and depending on size of file use ReadToEnd or ReadLine method. this two method return string and with on loop search and replace you characters and if use ReadToEnd method close file and write to file with System.IO.StreamWriter and if user ReadLine you must use temp file [Get temp address with string System.IO.Path.GetTempFileName()] and when reading and replacing complete delete main file [System.IO.File.Delete(string path)] and copy temp file System.IO.File.Copy(string path1,string path2)]
|
|
|
|
|
Sorry for late reply, due to sudden illness.
But friendz, none of the solution able to recognize the special character. is there some thing i m missing?
please reply.
|
|
|
|
|
I am creating a windows service where the employees get automatically logged into database when they start their computer. For this my service require the windows logged in username. Environment.UserName is not working. Is there any other tried solution?
puranonnet@hotmail.com
www.ibrinte.com
|
|
|
|
|
System.Security.Principal.WindowsIdentity.GetCurrent().Name will get you the user that the service is running as, but services generally run under special user accounts like "Local Service". Services also start before the user logs on so you can't just set it to run under the currently logged on user, because there might not be one.
Services aren't really meant to be tied to the logged on user. What would happen if you had two users logged on at the same time (which can happen). Perhaps you should consider making your app a normal client based app (but with no GUI) and stick a short cut to it in the start up menu.
You should also probably be using windows authentication instead of getting the user name.
Simon
|
|
|
|
|
hii
any one can tell that how make setting in enterprise library in the connection string there should be sqlconnection but i have 4.1 version of enterprise,in this there is option ORACLE PACKAGE in data access application block.
what the problem in this,is that installation problem
rizvan sivally
|
|
|
|
|
0. very very badly written statement/question.
1. Try the database[^] forum; tell them I sent you.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Hi forum............
Can anyone give my any sample for message handling. I am working on a program which should receive a message sent by any other program. These messages will be the keyboard keys (WM_KEYS). So please give me any example; how to handle a message sent by other application using SendMessage API.
Thanks in advance......
Vishal Moharikar.
|
|
|
|
|
Instead of using message passing using SendMessageAPI, i would recommend you to use FileWatcher. Let one application write in it and the other application read from it.
This is a better way of doing it.
Ahsan Ullah
Senior Software Engineer
MCTS 2.0
|
|
|
|
|
Hi Ahsan.......
Thanks for your quick solution.....but I can not use this solution. Actually the second application is pre-build and I can not modify it. Also the second application is written some other language which actually hooks the keyboard events and change its character to any desired language (other than English) character. Besides this task (character interchange) it sends the actual keyboard character to the calling application for its use.
This message passing is done via SendMessage API and I have no idea how to handle the messages. So please help; how can I receive the messages and use them.
Thanks once again....
Vishal Moharikar.
|
|
|
|