|
XMLSerialization is supported by .NET Compact Framework if it fits your needs
|
|
|
|
|
I'm going to have to concur with Giorgi - XMLSerialization should do the trick. I'm using it on a .NETCF app and it's great. I just adorned my objects and their properties with the appropriate Xml attributes and the XMLSerializer does the rest.
"If you think of yourselves as helpless and ineffectual, it is certain that you will create a despotic government to be your master. The wise despot, therefore, maintains among his subjects a popular sense that they are helpless and ineffectual."
- Frank Herbert
|
|
|
|
|
Patrick Sears wrote: I just adorned my objects and their properties with the appropriate Xml attributes
Thanks, XMLSerialization is just what I need, but I don't understand the bit about attributes. Could you please provide more information, or tell me where I might find it?
|
|
|
|
|
Sure!
The XmlSerializer by default will serialize an object's public properties and fields using the names in your object.
Say you have an object called Person, and it has a Name and a Gender.
public class Person
{
private string mName;
private string mGender;
public string Name
{
get;set;
}
public string Gender
{
get;set;
}
}
By default the XmlSerializer will create something that looks like this:
< Person>
<Name>Whatever</Name>
<Gender>Whatever</Gender>
</Person>
But you can adorn the object to change the way the object is serialized. For example, if you want it to be serialized as a "Human" and the Name and Gender properties to be XML attributes instead of XML elements:
[XmlType("Human")]
public class Person
{
private string mName;
private string mGender;
[XmlAttribute("Name")]
public string Name
{
get;set;
}
[XmlAttribute("Gender")]
public string Gender
{
get;set;
}
}
This will create XML that looks like this:
<Human Name="Whatever" Gender="Whatever" />
You can read more about the XmlSerializer and how to use it here:
http://msdn2.microsoft.com/en-us/library/system.xml.serialization.xmlserializer(vs.80).aspx[^]
and here:
http://msdn2.microsoft.com/en-us/library/ms950721.aspx[^]
"If you think of yourselves as helpless and ineffectual, it is certain that you will create a despotic government to be your master. The wise despot, therefore, maintains among his subjects a popular sense that they are helpless and ineffectual."
- Frank Herbert
|
|
|
|
|
All is now clear. Many thanks for your help
|
|
|
|
|
Glad I could help
"If you think of yourselves as helpless and ineffectual, it is certain that you will create a despotic government to be your master. The wise despot, therefore, maintains among his subjects a popular sense that they are helpless and ineffectual."
- Frank Herbert
|
|
|
|
|
|
Backgroundworker is an easy way to open a different thread in an higher level implementation to make an isolated operation. Theading requires sometimes more control about states, semaphors...
Visit my blog at http://dotnetforeveryone.blogspot.com/
|
|
|
|
|
Ultimately there is no difference as both will allocate a thread from the thread pool. The BackgroundWorker component is a "visual" component (something that can be dropped on to a form at design time) that was created to help simplify creating a multi-threaded application.
Using the background worker is not ideal for all situations and using it doesn't mean you shouldn't have an understanding of how threading behaves.
|
|
|
|
|
I am very new to C#. I need to create a Windows form that will read a SQL table and populate a treeview. I can connect to the DB, create the dataadapter, populate a data set. The problem is how to use the dataset to populate a treeview.
I have looked at a few examples here but none use a dataset, or the data structure was different and I could not modify to work with my data or the examples were more than I needed and too complex for a beginner. Can some one suggest a URL, book or show me an example of code that simply takes the data as shown and populates a treeview.
I would really appreciate the help.
Thank you.
I have a SQL Server 2005 table containing this data shown below.
Child Parent depth Hierachy
1 NULL 0 01
2 1 1 01.02
5 2 2 01.02.05
6 2 2 01.02.06
3 1 1 01.03
7 3 2 01.03.07
11 7 3 01.03.07.11
14 11 4 01.03.07.11.14
12 7 3 01.03.07.12
13 7 3 01.03.07.13
8 3 2 01.03.08
9 3 2 01.03.09
4 1 1 01.04
10 4 2 01.04.10
15 NULL 0 15
15 15 1 15.15
16 15 1 15.16
18 16 2 15.16.18
17 15 1 15.17
|
|
|
|
|
I need to send various ps2 commands to my keyboard as part of my apps functionality.
Example from the PS2 spec:
0xF5 = disable kybd
0XF2 = Read ID
Some commands like the Read ID also require the ability to get the response.
I Googled for awhile so I turn here for some ideas.
Thanks,
JayHart
|
|
|
|
|
PS2 as in Play Station? So your writing PS2 games using C#? Wow... I need to do some Googling! Good luck.
|
|
|
|
|
Nope, not playstation,
the old cruudy keyboard you plug into your PC instead.
Jay
|
|
|
|
|
I had a page fault
I have no experience using a keyboard for anything other than input.
|
|
|
|
|
I don't believe you can send any output beyond the status of the num, scroll, and capslock keys to change the indicator lights. You'll need to read up on the hardware implementation to match what your device is expecting to see with what signals are generated when the states of those keys are altered on the PC.
--
If you view money as inherently evil, I view it as my duty to assist in making you more virtuous.
|
|
|
|
|
|
Oh God...
SERIOUSLY, you need to pick up a book on C# for beginners. The questions you've asked go back to the frist day of any beginning programming class.
|
|
|
|
|
Does sound like a set of questions you'd get near the beginning of a programming course...
My current favourite word is: Waffle
Cheese is still good though.
|
|
|
|
|
Do I need to find J4amieC?
In case you didn't understand what Jamie said, you should STOP typing messages into forums and spend more time READING.
|
|
|
|
|
|
What am I doing wrong?
SqlConnection conn = new SqlConnection("Data Source=(local)\\SQLEXPRESS;Initial Catalog=opc;Integrated Security=True");
conn.Open();
SqlCommand selCmd = new SqlCommand("SELECT COUNT(*) FROM data WHERE timestamp>@pdate1 AND timestamp<@pdate2", conn);
SqlParameter date1 = new SqlParameter();
date1.ParameterName = @pdate1;
date1.Value = TextBox1.Text;
SqlParameter date2 = new SqlParameter();
date2.ParameterName = @pdate2;
date2.Value = TextBox2.Text;
selCmd.Parameters.Add(date1);
selCmd.Parameters.Add(date2);
int count = (int)selCmd.ExecuteScalar();
Label1.Text = count.ToString();
conn.Close();
I get 2 errors:
Error 1 The name 'pdate1' does not exist in the current context
Error 2 The name 'pdate2' does not exist in the current context
|
|
|
|
|
It should look like this:
date1.ParameterName = "@pdate1";
date2.ParameterName = "@pdate2";
|
|
|
|
|
Yes I found it few minute later...Thanks
But now I get another error.
protected void Button_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=(local)\\SQLEXPRESS;Initial Catalog=opc;Integrated Security=True");
conn.Open();
SqlCommand selCmd = new SqlCommand("SELECT COUNT(*) FROM data WHERE timestamp>@date1 AND timestamp<@date2", conn);
SqlParameter param1 = new SqlParameter();
SqlParameter param2 = new SqlParameter();
param1.ParameterName = "@date1";
param1.Value = TextBox1.Text;
selCmd.Parameters.Add(param1);
param2.ParameterName = "@date2";
param2.Value = TextBox2.Text;
selCmd.Parameters.Add(param2);
int count = (int)selCmd.ExecuteScalar();
Label1.Text = count.ToString();
conn.Close();
}
I get this Sql Exception:
Arithmetic overflow error converting expression to data type datetime.
In line "int count = (int)selCmd.ExecuteScalar();"
I need to count the rows between these two dates...
|
|
|
|
|
It means that when date1 and date2 are replaced with values from the textbox they are not formated correctly and inside the query they can't be compared. Try running the query manually in sql server to see what error you will get. Also, if I remember it correctly, datetime variables need ' in the query
|
|
|
|
|
I tried the below query
SELECT COUNT(*) AS Expr1
FROM data
WHERE (timestamp > 19 / 08 / 2007) AND (timestamp < 23 / 08 / 2007)
manually but got 0
The column is
19/8/2007 10:25:40 am
19/8/2007 10:25:59 am
20/8/2007 6:10:56 am
20/8/2007 6:11:49 am
20/8/2007 6:20:20 am
20/8/2007 6:20:32 am
20/8/2007 6:20:38 am
|
|
|
|