|
I usualy just store data in a DataSet and then you can save it and load it easily using xml binds. It's very easy.
DataSet t = new DataSet();
t.Tables.Add(someTable);
t.WriteXmlSchema("Filename");
t.WriteXml("Filename");
DataSet loaded = new DataSet();
loaded.ReadXmlSchema("Filename");
loaded.ReadXml("Filename");
|
|
|
|
|
Thanks. I will definitely explore that option.
|
|
|
|
|
SQL Server Compact Edition. It's like full blown SQL Server, with some limitations (e.g., 4GB database size limit, can't create stored procedures so you have to do everything with queries). The major advantage is that it gets installed with .Net, so it's already on their computers.
|
|
|
|
|
I was literally just reading about that. I think that's what I'm going to try first since I'm already familiar with the platform. Thanks for the reply.
|
|
|
|
|
Kris,
Before you spend time trying to figure how to get your users to access a local or remote database, take the time to determine if they need to access a database in the first place. Chances are you could easily get by saving your data to XML or a simple binary store using file I/O.
I'm reminded of the saying, "if the only tool you have is a hammer, every problem looks like a nail."
/ravi
|
|
|
|
|
Good morning.
I am trying to populate City and State fields based on a Zip entered and I am getting an Webservice Data at the root level is invalid. Line 1, position 1. error.
The XML return from the webservice is as follows:
<?xml version="1.0" encoding="utf-8" ?>
- <NewDataSet>
- <Table>
<CITY>Portland</CITY>
<STATE>ME</STATE>
<ZIP>04104</ZIP>
<AREA_CODE>207</AREA_CODE>
<TIME_ZONE>E</TIME_ZONE>
</Table> </NewDataSet>
My code is as follows:
private void btnZipWS_Click(object sender, EventArgs e)
{
XmlDocument doc = new XmlDocument();
Bank.net.webservicex.www.USZip ws = new Bank.net.webservicex.www.USZip(); XElement Results = XElement.Parse(ws.GetInfoByZIP (txtZip.Text).ToString());
foreach (XElement xe in Results.Elements("NewDataSet").Elements("Table").Descendants())
{
if (xe.Name == "CITY")
{
txtCity.Text = xe.Value;
}
if (xe.Name == "STATE")
{ txtState.Text = xe.Value;
}
}
}
Is there an issue with the XML being returned? I wasn't sure what the - signs were for.
Thank you, WHEELS
|
|
|
|
|
The most glaring thing is the hyphens before the root tags.
Further, your code should probably look more like this:
XElement element = Results.Elements("NewDataSet").Element("Table");
string city = element.Element("CITY").Value;
string state = element.Element("STATE").Value;
... blah blah
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
The problem I am having now is that th eLoad is looking for a physical XML file on my computer, but it is being called from a Web Service.
XDocument doc = XDocument.Load(ws.GetInfoByZIP(txtZip.Text).ToString());
private void btnZipWS_Click(object sender, EventArgs e)
{
Bank.net.webservicex.www.USZip ws = new Bank.net.webservicex.www.USZip();
XDocument doc = XDocument.Load(ws.GetInfoByZIP(txtZip.Text).ToString());
XElement element = Results.Elements("NewDataSet").Element("Table");
string city = element.Element("CITY").Value;
string state = element.Element("STATE").Value;
WHEELS
|
|
|
|
|
Since you're getting an XML string back from the web service, you want to use this:
XDocument doc = XDocument.Parse(textZip.Text);
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Hi John.
I am semi-following. I wouldn't be parsing the txtZip.Text. That is a textbox on the form and the data is being passed to the WS call.
XDocument doc = XDocument.Parse(ws.GetInfoByZIP(txtZip.Text).ToString());
When I use this, I am getting this error:
Data at the root level is invalid. Line 1, position 1.
WHEELS
|
|
|
|
|
Like I said in my original response - you have hyphens preceding the two root-most elements. That makes your XML invalid.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Very new to XML. What do I do to compensate for the - s? WHEELS
|
|
|
|
|
it is not valid XML as long as those hyphens are there. Eradicate them.
|
|
|
|
|
|
Isn't that what I told you, too?
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Hi John.
I believe you did. Having a very challenging time with this XML/WebService, and didn't expect to enough these hypens.
Thanks again.
WHEELS
|
|
|
|
|
I'm working on a project as we speak that's getting XML from a SQL database stored procedure via a web service, and I'm not getting any hyphens. Can I assume you solved your problem?
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Found a work around, although not as elegant as I would like:
Bank.net.webservicex.www.USZip ws = new Bank.net.webservicex.www.USZip();
XmlNode cityNode = ws.GetInfoByZIP(txtZip.Text);
string cityName = "UNKNOWN";
string stateName = "UNKNOWN";
foreach (XmlNode node in cityNode)
{
foreach (XmlElement elem in node)
{
if (elem != null && elem.Name.Equals("CITY"))
{
cityName = elem.FirstChild.InnerText;
}
if (elem != null && elem.Name.Equals("STATE"))
{
stateName = elem.FirstChild.InnerText;
}
}
}
txtCity.Text = cityName;
txtState.Text = stateName;
WHEELS
|
|
|
|
|
HI everyone, I have an application in VSC++/CLI and this is how I request data from the device.
serialPort->Write(String::Concat("P", Char(4).ToString(), Char(54).ToString(), "@"));
P = first Character and
@ = is the last Character.
Char(4) is the number of arguments.
Char(54) is the packet number for example.
my device knows what to send when I ask this.
My question is how do I do the same in C#.
thanks
|
|
|
|
|
This[^] article should help. Also see the String [^] class.
/ravi
|
|
|
|
|
Hi,
you could do exactly the same thing in C#, however I would prefer using a byte array, as not all data items are textual:
byte[] request=new byte[] {(byte)'P', 4, 54, (byte)'@'};
mySerialPort.Write(request, 0, 4);
|
|
|
|
|
Hi Luc Pattyn, I am trying it now then I will let you know if it works.
thanks much.
|
|
|
|
|
Hi Luc Pattyn, I am still have problem with the serialPort communicaiton.
I can send request to the device and device is responding but I don't get
any data back. I know the the device is sending data because my other
program shows it.
c# application getting no data don't know why.
if (serialPort1.IsOpen)<br />
serialPort1.Close();<br />
serialPort1.Open();<br />
byte[] request = new byte[] { (byte)'P', 4, 40, (byte)'@' };<br />
serialPort1.Write(request, 0, 4);<br />
textBox1.Text = serialPort1.BytesToRead.ToString();
|
|
|
|
|
your target device needs some time to react to the command you send it. It has to:
- get aware there is some data coming in;
- interpret the command;
- execute the command;
- send a response.
The last step probably is the slowest: at 9600 Baud each character takes around 1 millisecond, so a string of 10 characters is in transit for 10 milliseconds. Not a single character will be received in zero time, which is what you allowed for.
Normally serial data is received in an asynchronous fashion, either using the DataReceived event, or by having another thread performing a Read() ahead of time.
As a first experiment, insert a Thread.Sleep(100); right after your port.Write statement.
|
|
|
|
|
First; I wouldn't use Concat -- I never have. I'd use either String.Format or let the serialport class do that.
Second; Why do you have Char(4).ToString() and Char(54).ToString() ? Can't they be stored in constants? e.g. const string Char4 = "\u0004" ;
|
|
|
|