|
something there for Read File structured text to listview in C #, share me with, I need to see, thank you
|
|
|
|
|
Can you tell us what Your Text file look like ?
|
|
|
|
|
What have you tried? Taken a look at filehelpers and the articles here on CodeProject?
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
I have a C# 2010 application that I would like to add the following lines of code:
eDataContext rData = new eDataContext();
DateTime complete_date = (DateTime)(from a in rData.cust
where a.PkID == pkId
select a.Complete_Date).FirstOrDefault();
if (complete_date != null)
The linq statement where DateTime complete_date is assigned a value works.
However when I try to executed the line of code
(complete_date != null),
the program has a problem on this line of code. I found this out by stepping though the code.
Thus can you tell me why the
"if (complete_date != null)" line of code is having a problem? Also can you tell me what to do to solve the problem?
|
|
|
|
|
DateTime is not nullable. If you need to have a null date option, use DateTime? to declare it inside. This tells the compiler to create it as nullable.
|
|
|
|
|
FirstOrDefault is your clue. If not found, it will return the default value for DateTime which is DateTime.MinValue .
Use:
if (complete_date != DateTime.MinValue)
Or
if (complete_date != default(DateTime))
instead.
null is default for reference types such as classes and interfaces, for value types such as structs there is normally a static readonly field or property available such as MinValue or Empty , or you can use the parameterless constructor to get the default, or default(...) as above.
|
|
|
|
|
DateTime is a ValueKind, so comparing it with null isn't very useful (it'll always not be null).
If your LINQ query doesn't find any rows, then FirstOrDefault() will return a default instance of the requested data type (DateTime, in this case).
There's a clue in the name
If you want to know if you found any rows or not, either test the query first (e.g. Any()) before evaluating First(), or compare the returned value with the default DateTime value (DateTime.MinValue, IIRC). If you do that however, you won't be able to tell the difference between no rows, and rows where the first had the minimum datetime value.
|
|
|
|
|
I am using string queries
SELECT CASE WHEN COALESCE(title2, title)='RUNTIME PARAMETER' in function.
It is ok but I want them not to be written in the function because anyone developer can mess it up. There will be lot of queries which will get run time parameters also from functions.
I want it somewhere so that it is safe. But it should be available during run time, means if i want to replace a query the i should be able to so that without the need of building and deploying the files.
One way i was thinking is to use either resource files or config files but i cannot make mind. I don't want the performance to take a hit yet to maintain flexibility and maintainability.
Using resource files means to load read text which will incur some performance loss but is better than config files as they are not safe and easily readable.
Any suggestion?
|
|
|
|
|
Well, the performance hit of a resource file is negligible so I would go that way if I were you.
|
|
|
|
|
I have a question about a C# 2008 application that calls C# 2008 application by using 'Process exec_calc = new Process();'. Curretnly the first C# 2008 application creates output excel spreadsheets that are emailed out to customers.
Now the first C# application will count the number of rows that are generated on the excel spreadsheet. The first program will insert a new row into a customer table that is setup by customer number and count in a sql server 2008 r2 database. Now the first program will call the second C# application and pass that program the customer number.
When the second C# program runs, it will obtain the customer number from the arguements that where passsed to it. Now the second C# program will read the Customer table to obtain the row that was inserted into the customer table by the first C# program.
This process will continue until all of the customer records have been processed.
The second program will now call a web service with this information. This design needs to stay since 95% of the entire new design has been tested and works. This design will stay since it will make the code production ready within a few weeks.
My question is updating and accessing the customer table. Will I have any deadlock issues? Do I need to consider permission problem(s) and/or access problems that I need to consider? If so, what are the problems and what do I need to do to solve the problem(s)?
|
|
|
|
|
Hi everyone,
I want to make a simple media player in C# and I used QuartzTypeLib library to read the video and this perfect. But, in the next step I want my player to support ability to add subtitle to the movie.
I googled it but i didn't find any thing that simple and useful for me.
Can any one help, please.
Thanks in advance.
|
|
|
|
|
Does answer # 9 in this[^] thread help?
/ravi
|
|
|
|
|
I think yes.
the second solution(I know it before) is better but i can't know how to use in C#. If you give me a link for that, please.
The first solution I don't understand completely but I prefer to use the first solution.
Thanks in advance.
|
|
|
|
|
Hi,
Here is my question...
I need to design two windows forms applications in such a way that the Form 1 will run for some time and then starts Form 2 in a new thread. Once the Form2 is started I need to update the labels on both the forms simultaneously.
Form1
public Form1()
{
Initialize();
DoSomeOperations();
}
public void DoSomeOperations()
{
updateLabel("Form 1");
Thread.Sleep(10000)
var task1= new Thread (() =>Form2()) {"GUIThread"};
task1.Start();
}
public void Form2()
{
Form2 f2= new Form2();
Application.Run(f2);
}
void updateLabel(string message)
{
label1.text = message; //label in Form1
label1.Refresh();
}
After Form2 is started, I wanted to update the label in Form 1 and Form2 at the same time. That is what ever message I get in Form 1, I need to display it both on Form 1 and Form2. I tried toraise an event in Updatelabel method and assigned the event to a method in the constructor of Form2 but it didnt work. Can somebody please help me with this?
Thanks in advance
|
|
|
|
|
|
You do not start a new form in a new thread. All GUI components get created and are manipulated by the startup thread.
Your work goes on background threads and if they have to manipulate controls, they Invoke calls to method to do the manipulations on the GUI thread.
|
|
|
|
|
Thank you guys...
I followed both your suggestion. Firstly I am not starting
the other form in a new thread. Instead I used the property Show().
Form2 f2= new Form2()
f2.Show() //Instead of Application.Run(f2)
and then made the label which I want to update on Form2 as internal. So I had direct access to it from Form1.
|
|
|
|
|
Hi,
create a global delegate so that the delegate can be access from both Form1 and Form2.
public delegate void LabelUpdateDel();
create an instance of the delegate in Form1.
public LabelUpdateDel lblUpdateDel;
I believe you are showing the Form2 from Form1.
so attach a Form1 method with the delegate before showing Form2.
Form2.lblUpdateDel=MethodUpdateLabel; // MethodUpdateLabel is in Form1.
Form2.Show();
private void MethodUpdateLabel ()
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(MethodUpdateLabel ));
}
else
{
lblForm1.Text = "your text";
}
}
Now the method DoSomeOperations() is look like
public void DoSomeOperations()
{
..
lblForm2.Text="Your text";
if(lblUpdateDel!=null)
{
lblUpdateDel();
}
}
thats all.
|
|
|
|
|
For a C# 2010 application, I would like to be able to check for the value
returned by the linq to sql query listed below as being null.
Is there any way to check for
strOrgName == null?
var strOrgName = (from o in rData.Orgs
join pl in rData.Custs on o.OrgID equals pl.OrgID
where pl.orgnum == strContract
select o.OrgName).FirstOrDefault();
The code I have written so far only allows if I check for
strOrgName != null.
I am using the code above to use as an example of how I would like to be able
check for the value returned being a null.
Thus can you tell me how to solve my isuse?
modified 29-Sep-12 17:16pm.
|
|
|
|
|
dcof wrote: The code I have written so far only allows if I check for strOrgName != null.
If you can check for != then you can check for == ; how are you doing the test?
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Hi.
I need to do a project for school in which I want to have an option to encrypt and decrypt a text file (possibly large one). I want to do it without using the cryptography classes of C#. my question is what's the best way of doing it? I read here that the RSA method is only suitable for small data, so what do I use for large data, and can I combine it with the RSA? How dO I start this kind of project?
thank you.
|
|
|
|
|
May be you should give AES (Rijndael) a try :
You can use this classes for testing
Here[^]
BTW:
RSA is one of C# classes
|
|
|
|
|
|
e are creating a class library project. The project will be using TDD approach so we will be using DI. but other than that what can be the ways [designs] to make it maintainable and scalable as this will be a big library.
|
|
|
|
|
If this will be big. Don't make it. Instead split it to handful of libraries, services, logic, data access, contracts, extensions, user controls etc.
No more Mister Nice Guy... >: |
|
|
|
|