|
Hi all ,
I would like to know , when -in practice-
do we need object serialization over writing object fields directly to Database?
|
|
|
|
|
When you want to simplify your DB code so you can just serialise the entire object in one step. You're basically getting the system to write that code for you, to store the individual values, read them back and restore the state of an object. Also, serialisation can be used in places where the framework doesn't let you write your own code.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
|
I am trying to take the some information from a txt file and use them as values for variables. I am in the development stage and just trying to get a hang of what exactly is required to do this and then build up.
CODE:
using System;
using System.IO;
public class TextFromFile
{
private const string FILE_NAME = "e:\\test.txt";
public static void Main(String[] args)
{
if (!File.Exists(FILE_NAME))
{
Console.WriteLine("{0} does not exist.", FILE_NAME);
Console.Read();
return;
}
using (StreamReader sr = File.OpenText(FILE_NAME))
{
String fromtxt;
int IntValue;
while ((fromtxt = sr.ReadLine()) != null)
{
Console.WriteLine(fromtxt);
IntValue = Convert.ToInt32(fromtxt);
Console.WriteLine(IntValue);
}
Console.WriteLine("The end of the stream has been reached.");
Console.Read();
sr.Close();
}
}
}
In my case I have the text file simply have the number 5 written so the expected output is:
5
5
The end of the stream has been reached.
When I put:
while ((fromtxt = sr.ReadLine()) != null)
{
Console.WriteLine(fromtxt);
}
IntValue = Convert.ToInt32(fromtxt);
Console.WriteLine(IntValue);
I get the output:
5
0
When Keep put
while ((fromtxt = sr.ReadLine()) != null)
{
Console.WriteLine(fromtxt);
IntValue = Convert.ToInt32(fromtxt);
Console.WriteLine(IntValue);
}
Console.WriteLine(IntValue);
I get the error message:
Error 1 Use of unassigned local variable 'IntValue
|
|
|
|
|
The code inside the while loop you suggest might never be executed and the variable IntValue will not be assigned.
if you do someshing like:
IntValue = Int32.MinValue;
while ((fromtxt = sr.ReadLine()) != null)
{
Console.WriteLine(fromtxt);
IntValue = Convert.ToInt32(fromtxt);
Console.WriteLine(IntValue);
}
Console.WriteLine(IntValue);
The code will compile but that is bad logic.
you can also do something like:
IntValue = Int32.MinValue;
bool hasData = false;
while ((fromtxt = sr.ReadLine()) != null)
{
Console.WriteLine(fromtxt);
IntValue = Convert.ToInt32(fromtxt);
Console.WriteLine(IntValue);
hasData = true;
}
if(hasData)
{
Console.WriteLine(IntValue);
}
About the parsing. you should use :
bool parseOK = Int32.TryParse(fromtxt, out IntValue );
if(parseOK )
{
Console.WriteLine(IntValue);
hasData = true;
}
else
{
Console.WriteLine("Error the data is not an integer");
}
Natza Mitzi
|
|
|
|
|
In my program I have a DataGridView control on each TabPage in a TabPageControl, all DataGridViews have the same number and kind of columns. Now when the user clicks Print I want to amalgamate all the rows into one large DataGridView and print it. The first part is obvious but how would I print only the DataGridView?
|
|
|
|
|
You wouldn't, b/c the control itself never shows all the records. You'd iterate over the record set and write seperate printing code to print it all.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
|
If you start printing the second datagrid from the point on the page that the first one ends at, and so on, you should get effectively one printed grid.
|
|
|
|
|
hi
how can i paint all rows in Datagrid that the value of filed Age = 30 in red ?
i work in WinCE
thank's for any help
|
|
|
|
|
Welcome to CP, try posting your question in the Mobile Dev. forum, as it probably will get a more targeted response.
|
|
|
|
|
i have got a programme which makes the computer faster and this programme consist of bios time.
and i want to set up the system clock . how can i do that ?
best regards.
|
|
|
|
|
...what?
You have a program that makes the computer faster... and the program is made up of the "bios time"?
You want to set up the system clock??
What the hell are you talking about?!
|
|
|
|
|
|
Uhhh, changing the time doesn't make a computer faster... Unless you're "fudging" your results.
|
|
|
|
|
I'm thinking he means overclock instead of system clock...
|
|
|
|
|
Oh, I figured as much. I was wondering if the OP knew what he was talking about. Apparently not...
|
|
|
|
|
hi
my programme's name is speeder xp. this programme makes cpu faster.
i will build a programme which makes speeder xp,etc stop. and it is said that is connected with bios clock.
thats why i ask you that question .
sorry for my english.
thanks.
|
|
|
|
|
Speeder XP (as I guessed) Overclocks the CPU. Be very VERY careful with this, it can damage your PC by causing your processor to overheat. It is recommended NOT TO OVERCLOCK your PC without the proper cooling modifications!
As for your OP, you did not ask any .net related question.
This has NOTHING to do with time or the system clock, this is configuring your processor to operate above the normal safety specifications!
USE IT AT YOUR OWN RISK
|
|
|
|
|
thank you.
how can i fix this ?? how can i control this settings in c# ??
|
|
|
|
|
Hi,
what I would like to do is this:
I want to create a C# programm which runs in the background. Then, when I press e.g. Alt+F12 from anywhere in Windows, it should maximize (!) that programm.
Anyone knows how to do something like that? I was searching hours for hotkey generators but didn't find anything good. So I figured might be better to programm the whole thing myself.
Would be happy about some help .
Sincerely,
Christian K.
|
|
|
|
|
You might have to use a global keyboard hook to process the keys, otherwise your .net application will only have scope over the keyboard for when your application has focus.
|
|
|
|
|
thanks! don't really know what you mean with global keyboard hook ... do you have any kind of link or tutorial where could read myself into that topic?
thanks again!
ck
|
|
|
|
|
|
You don't need global hook for hotkeys. You can do it using a little bit of P/Invoke and your application will be notified whenever the hotkey is pressed. See here: Hotkeys[^]
|
|
|
|