|
Thanks Mr Minute for your response. I will keep that in mind for sure.
So i tried debugging my code, and I notice that the code does not go anywhere once I click on the validate button. Meaning it does not go to the validate function. It shows me error as follows "Illegal character paths"
I think the problem is with this function paramters "ValidateXML(strXML, strXSD, "urn:bookstore-schema");"
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Xml;
using System.Xml.Schema;
namespace ValidateXML
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string strXML;
string strXSD;
string strXSDNS;
void ValidateXML(string strXML, string strXSD, string strXSDNS)
{
XmlValidatingReader reader = null;
XmlSchemaCollection myschema = new XmlSchemaCollection();
try
{
StreamReader streamReader = new StreamReader("C:/Umar/1234_H1N1_00002.xml");
strXML = streamReader.ReadToEnd();
streamReader.Close();
StreamReader streamReader1 = new StreamReader("C:/Umar/H1N1_Schema.xsd");
strXSD = streamReader1.ReadToEnd();
streamReader.Close();
XmlDocument doc = new XmlDocument();
doc.Load(strXML);
string xmlFrag = doc.InnerXml;
XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None);
reader = new XmlValidatingReader(xmlFrag, XmlNodeType.Element, context);
myschema.Add(strXSD, strXSD);
reader.ValidationType = ValidationType.Schema;
reader.Schemas.Add(myschema);
while (reader.Read())
{
}
output.Text = "Completed validating " + strXML;
}
catch (XmlException XmlExp)
{
output.Text = "XMLException " + XmlExp.Message;
}
catch (XmlSchemaException XmlSchExp)
{
output.Text = "XMLSchemaException " + XmlSchExp.Message;
}
catch (Exception GenExp)
{
output.Text = "Exception " + GenExp.Message;
}
}
private void btn_Validate_Click(object sender, EventArgs e)
{
String a = null;
String b = null;
if (txt_inputXML.Text == String.Empty)
{
output.Text = ("Warning: Upload a XML file");
}
else if (txt_inputXSD.Text == String.Empty)
{
output.Text = ("Warning: Upload a XSD File");
}
else
{
output.Text = "yoo";
ValidateXML(strXML, strXSD, "urn:bookstore-schema");
}
}
private void btn_BrowseXML_Click(object sender, EventArgs e)
{
OpenFileDialog openFile1 = new OpenFileDialog();
openFile1.Filter = "(*.xml)|*.xml";
if (openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
txt_inputXML.Text = openFile1.FileName;
}
}
private void btn_BrowseXSD_Click(object sender, EventArgs e)
{
OpenFileDialog openFile1 = new OpenFileDialog();
openFile1.Filter = "(*.xsd)|*.xsd";
if (openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
txt_inputXSD.Text = openFile1.FileName;
}
}
}
|
|
|
|
|
waqasm wrote: I think the problem is with this function paramters "ValidateXML(strXML, strXSD, "urn:bookstore-schema");"
I can see nothing wrong with that line as such.
However, there are two things that I have spotted in your ValidateXML method.
The
myschema.Add(strXSD, strXSD);
line is incorrect. It uses strXSD ("urn:bookstore-schema") for both parameters, strXSD is the namespace to use. The second parameter should be the URL of the file containing the schema to use.
Secondly you should not be using XmlSchemaCollection as it is Obsolete unless you are using .Net 1.0 or 1.1.
It will still work but you should really be using XmlSchemaSet instead.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hey,
I fixed what you had asked me to fix. But i am getting this error in my output box. "Exception Illegal characters in path."
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Xml;
using System.Xml.Schema;
namespace ValidateXML
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string strXML;
string strXSD;
string strXSDNS;
void ValidateXML(string strXML, string strXSD, string strXSDNS)
{
XmlValidatingReader reader = null;
XmlSchemaSet myschema = new XmlSchemaSet();
ValidationEventHandler eventHandler = new ValidationEventHandler(ShowCompileErrors);
try
{
XmlDocument doc = new XmlDocument();
doc.Load(strXML);
string xmlFrag = doc.InnerXml;
XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None);
reader = new XmlValidatingReader(xmlFrag, XmlNodeType.Element, context);
myschema.Add(strXSD, "C:/Umar/C:/Umar/H1N1_Schema.xsd");
reader.ValidationType = ValidationType.Schema;
reader.Schemas.Add(myschema);
while (reader.Read())
{
}
output.Text = "Completed validating " + strXML;
}
catch (XmlException XmlExp)
{
output.Text = "XMLException " + XmlExp.Message;
}
catch (XmlSchemaException XmlSchExp)
{
output.Text = "XMLSchemaException " + XmlSchExp.Message;
}
catch (Exception GenExp)
{
output.Text = "Exception " + GenExp.Message;
}
}
private void button1_Click(object sender, EventArgs e)
{
String a = null;
String b = null;
if (txt_inputXML.Text == String.Empty)
{
output.Text = ("Warning: Upload a XML file");
}
else if (txt_inputXSD.Text == String.Empty)
{
output.Text = ("Warning: Upload a XSD File");
}
else
{
output.Text = "yoo";
ValidateXML(strXML, strXSD, "urn:bookstore-schema");
}
}
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog openFile1 = new OpenFileDialog();
openFile1.Filter = "(*.xml)|*.xml";
if (openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
txt_inputXML.Text = openFile1.FileName;
}
}
private void button3_Click(object sender, EventArgs e)
{
OpenFileDialog openFile1 = new OpenFileDialog();
openFile1.Filter = "(*.xsd)|*.xsd";
if (openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
txt_inputXSD.Text = openFile1.FileName;
}
}
}
ps. I was told that this website has tons of experienced programmers?? Why is there only one person helping me out
|
|
|
|
|
There is one obvious line in your code, that might be causing your exception:
myschema.Add(strXSD, "C:/Umar/C:/Umar/H1N1_Schema.xsd");
What is "C:/Umar/C:/Umar/H1N1_Schema.xsd" ?
If it is supposed to be "C:\Umar\H1N1_Schema.xsd" , then try:
myschema.Add(strXSD, @"C:\Umar\H1N1_Schema.xsd");
waqasm wrote: ps. I was told that this website has tons of experienced programmers?? Why is there only one person helping me out
This site does indeed have lots of experienced programmers. All of us help out, when we can, on a voluntary basis. On problems that interest us, for people who give full information about the problems they are having. Little things like what line in the code the error occurs on. Also, in general they do not like to interrupt, unless they see some obviously bad advice.
So, if you do not like the help that you are getting, for free, please feel free to ask elsewhere. If you do, however, I would suggest that you learn to use the debugger, which for all of your problems would have helped you to identify the problems for yourself, and include the information in your question.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Yes, I know the help here is for free. But im sure that everyone benefits from knowledge, whether they are helping someone or being helped. I did manage to use the debugger, so thank you for your professional advice.
Anyhow, the code is finished so anyone having trouble with what I'm doing can benefit from my code.
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Xml;
using System.Xml.Schema;
namespace ValidateXML
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string strXML;
string strXSD;
private void button1_Click(object sender, EventArgs e)
{
if (txt_inputXML.Text == String.Empty)
{
output.Text = ("Warning: Upload a XML file");
}
else if (txt_inputXSD.Text == String.Empty)
{
output.Text = ("Warning: Upload a XSD File");
}
else
{
strXML = txt_inputXML.Text;
strXSD = txt_inputXSD.Text;
XmlValidatingReader reader = null;
XmlSchemaCollection myschema = new XmlSchemaCollection();
try
{
XmlDocument doc = new XmlDocument();
doc.Load(strXML);
string xmlFrag = doc.InnerXml;
XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None);
reader = new XmlValidatingReader(xmlFrag, XmlNodeType.Element, context);
reader.ValidationType = ValidationType.Schema;
myschema.Add("http://tempuri.org/dsMinistryH1N1Export.xsd", strXSD);
reader.Schemas.Add(myschema);
while (reader.Read())
{
}
output.Text = ("Completed validating " + strXML);
}
catch (XmlException XmlExp)
{
output.Text = ("XMLException " + XmlExp.Message);
}
catch (XmlSchemaException XmlSchExp)
{
output.Text = ("XMLSchemaException " + XmlSchExp.Message);
}
catch (Exception GenExp)
{
output.Text = ("Exception " + GenExp.Message);
}
}
}
private void button2_Click(object sender, EventArgs e)
{
OpenFileDialog openFile1 = new OpenFileDialog();
openFile1.Filter = "(*.xml)|*.xml";
if (openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
txt_inputXML.Text = openFile1.FileName;
}
}
private void button3_Click(object sender, EventArgs e)
{
OpenFileDialog openFile1 = new OpenFileDialog();
openFile1.Filter = "(*.xsd)|*.xsd";
if (openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
txt_inputXSD.Text = openFile1.FileName;
}
}
}
}
|
|
|
|
|
SqlCeConnection SqlCeConn = new SqlCeConnection(Information.ConnectionString);
SqlCeCommand SqlCeComm = new
SqlCeCommand("SELECT * FROM SystemUsers ", SqlCeConn);
try
{
if (SqlCeConn.State == ConnectionState.Closed)
SqlCeConn.Open();
SqlCeDataReader SqlRd = SqlCeComm.ExecuteReader();
if (SqlRd.Read()==true){}
when I run this code I get the error below. I could not find the reason behind it. I found that IF the query is wrong this type of error could occur but my query is totally works fine.
There was an error parsing the query. [ Token line number = 1,Token line offset = 8,Token in error = , ]
|
|
|
|
|
try the following...
<code>
public string ExecuteScalar(string strConnectionSring, string strScript)
{
SqlConnection ObjSqlConnection = null;
SqlCommand ObjSqlCommand = null;
ObjSqlConnection = new SqlConnection(strConnectionSring);
string strMessage = null;
try
{
ObjSqlCommand = new SqlCommand(strScript, ObjSqlConnection);
ObjSqlConnection.Open();
ObjSqlCommand.ExecuteScalar();
strMessage = "Succes";
}
catch (Exception ex)
{
strMessage = ex.Message.ToString();
}
finally
{
ObjSqlConnection.Close();
ObjSqlCommand = null;
ObjSqlConnection = null;
strScript = null;
}
return strMessage;
}</code>
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.
Thanks
Md. Marufuzzaman
|
|
|
|
|
Thanks for your help. You saved my life . I have tried it and it has worked fine. Moreover could you explain how I can fetch the query result ?
|
|
|
|
|
You are most welcome...
Well.... You just need to use dataset to fetch query results....
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.
Thanks
Md. Marufuzzaman
|
|
|
|
|
I have no idea about dataset could yo explain it ?
however I tried SqlCeDataReader SqlRd= ObjSqlCeCommand.ExecuteReader(); instead of ObjSqlCeCommand.ExecuteScalar();
and to check if result row number > 0 I used "if (SqlRd.Read() == true)" conditional check. Unfortunately It does not works for query string "SELECT Username, Name, Surname FROM SystemUsers where Username =' " + input + "' and Password = '" +passwd +"'"; there must be one row as a result but It does not return any thing. do you have any idea ?
|
|
|
|
|
use this :
SqlCeDataReader reader;
using (reader = ObjSqlCeCommand.ExecuteReader())
{
while(reader.Read())
{
}
}
|
|
|
|
|
thank you very much
|
|
|
|
|
SqlCommand..::.ExecuteScalar Method:
Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.
SqlCommand.ExecuteReader Method:
Sends the CommandText to the Connection and builds a SqlDataReader.
Dataset:
http://msdn.microsoft.com/en-us/library/system.data.dataset.aspx
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.
Thanks
Md. Marufuzzaman
|
|
|
|
|
I am developing an application in which a connection to a server application on another computer within our network is established. I am using a System.Net.Sockets.Socket to establish the connection to said server app. Upon successfully connecting to the server app, I send a connect message with the login credentials the user provided. In response, the server app should send back a message to indicate a successful or unsuccessful login. My problem is this: when running from within the Visual Studio development, it works flawlessly. When I launch the executable directly, I do not receive the return message from the server app. Any ideas?
|
|
|
|
|
Do you log all exceptions? What are the symptoms other than "it does not work"?
Maybe you gave VS a permanent green light in your firewall, and it is blocking your app outside VS?
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Luc:
No firewalls are on between "here" and "there". No exceptions are being thrown. The server application is logging the receipt of the message from the client application.
|
|
|
|
|
Odd. Did you try debug build running inside VS? release build running inside VS? debug build double-clicked in bin\debug folder? release build double-clicked in bin\release folder?
the difference would be optimizations (timing difference or bugs), and error handling (VS settings influence some).
Do you use time-outs? with sufficient value? and failures get logged? or is the client hanging, waiting on a reply?
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Luc:
There was one point where I was missing code in a catch statement. That was the exception that was getting thrown. After I added code to handle that exception, I discovered that the problem was stemming from a difference in the amount of data included in the message sent from my Test tier versus my local tier. Due to this size difference, a flaw in my received handler was being tripped. Fixed my code and everything works as expected.
Thanks for your question about exceptions. If forced me to go back and check all of my catch statements.
Tim
|
|
|
|
|
yep. catching and somehow showing all exceptions is a powerful technique.
whenever I see an empty catch statement (and that is quite frequently around here, some people think it is wise to skip or postpone error handling), I make sure the perpetrator will not forget about it any time soon ...
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Hi, I'm creating an asp.net Pizza order form using c# for a night school course and I have a RadioButtonList for the Size of the pizza and a checkbox list for the Pizza Toppings. Both controls have autopostback enabled so that as a size is selected and a topping is added the Total Price label will automatically calculate the total price and size is selected and toppings added. I have a simple method that adds the ingredients price to the size price as selctions are made. The problem is that the value of the Total Price changes as selections are made to the size (2,4,6,8,10) but if a topping is selected then the value of the total price doesn't add the size price to the toppings price they are still calculated individually, can someone tell from my code how i can write and use my method to total the size price with the topping price? thanks in advance.
<br />
public partial class _Default : System.Web.UI.Page <br />
{<br />
decimal TotalPrice = 0;<br />
decimal IngredientsPrice = 0;<br />
decimal SizePrice = 0;<br />
<br />
private decimal MethodTotalPrice(decimal MethodIngredientsPrice,<br />
decimal MethodSizePrice)<br />
{<br />
decimal MethodTotalPrice;<br />
MethodTotalPrice = MethodIngredientsPrice + MethodSizePrice;<br />
return MethodTotalPrice;<br />
}<br />
<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
<br />
}<br />
protected void RadioButtonList1_SelectedIndexChanged1(object sender, EventArgs e)<br />
{<br />
lblSize.Text = rblSize.SelectedItem.Text;<br />
<br />
if (rblSize.SelectedValue == "Slice")<br />
{<br />
lblSize.Font.Size = 8;<br />
SizePrice = 2;<br />
}<br />
if (rblSize.SelectedValue == "Small")<br />
{<br />
lblSize.Font.Size = 10;<br />
SizePrice = 4;<br />
}<br />
if (rblSize.SelectedValue == "Medium")<br />
{<br />
lblSize.Font.Size = 12;<br />
SizePrice = SizePrice + 6;<br />
}<br />
if (rblSize.SelectedValue == "Large")<br />
{<br />
lblSize.Font.Size = 14;<br />
SizePrice = 8;<br />
}<br />
if (rblSize.SelectedValue == "Xtra Large")<br />
{<br />
lblSize.Font.Size = 16;<br />
SizePrice = 10;<br />
}<br />
TotalPrice = MethodTotalPrice(IngredientsPrice, SizePrice);<br />
lblPriceTotal.Text = TotalPrice.ToString();<br />
}<br />
protected void cblIngredients_SelectedIndexChanged(object sender, EventArgs e)<br />
{<br />
string Message;<br />
Message = "";<br />
for (int i = 0; i < cblIngredients.Items.Count; i++)<br />
{<br />
if (cblIngredients.Items[i].Selected)<br />
{<br />
Message = Message + cblIngredients.Items[i].Text + "<br>";<br />
IngredientsPrice = IngredientsPrice + 1;<br />
}<br />
}<br />
lblIngredients.Text = Convert.ToString(Message);<br />
TotalPrice = MethodTotalPrice(IngredientsPrice, SizePrice);<br />
lblPriceTotal.Text = TotalPrice.ToString();<br />
}<br />
}<br />
|
|
|
|
|
Marcus Farrugia wrote: SizePrice = SizePrice + 6;
Probably not intended
I mean, if you switch from Xtra large to medium, you're suddenly paying 16, right?
Marcus Farrugia wrote: IngredientsPrice = IngredientsPrice + 1;
AKA IngredientsPrice++ , just a style thing though. More important is that you don't reset it. It will just keep going up. That is not good.
Concatting "many" strings using the + operator is poor form, better use a StringBuilder , but that's not causing your problem.
Marcus Farrugia wrote: MethodTotalPrice = MethodIngredientsPrice + MethodSizePrice;
Surprising calculation, but if it's supposed to work that way...
edit: right ASP.NET. Ok ignore this post. Why do people just keep posting ASP.NET questions here instead of at the ASP.NET forum? Last modified: 45mins after originally posted --
|
|
|
|
|
harold aptroot wrote: Why do people just keep posting ASP.NET questions here
For the same reason they keep advertising ASP.net jobs as C# jobs.
|
|
|
|
|
Hi,
When one choice changes, how are you going to keep the result from another choice made earlier? The page reloads, doesn't it? With new variables, initialized at zero?
the easiest and safest way is to calculate total prize in a separate method that collects all required data;
then invoke that method from within all your Changed handlers. So every change recalculates the total price.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Well your code is a bit of a mess. As Luc has pointed out, ASP.NET will reset each of those class variables to zero on postback. There is the option of persisting values between postbacks but a more elegant solution would be to calculate the price whenever you need it.
I would approach this as follows, start with a method to do the actual proce calculation
private decimal CalculatePrice()
{
decimal sizePrice = 0;
switch(rblSize.SelectedValue)
{
case "Slice": sizePrice = 8;break;
case "Small": sizePrice = 10;break;
}
decimal ingredientsPrice = 0;
for (int i = 0; i < cblIngredients.Items.Count; i++)
{
if (cblIngredients.Items[i].Selected)
{
ingredientsPrice ++;
}
}
return sizePrice + ingredientsPrice ;
}
Next have this method called when either action is performed
protected void RadioButtonList1_SelectedIndexChanged1(object sender, EventArgs e)
{
decimal totalPrice = CalculatePrice();
lblPriceTotal.Text = totalPrice.ToString();
)
protected void cblIngredients_SelectedIndexChanged(object sender, EventArgs e)
{
decimal totalPrice = CalculatePrice();
lblPriceTotal.Text = totalPrice.ToString();
}
|
|
|
|
|
Marcus Farrugia wrote: I'm creating an asp.net Pizza order form using c# for a night school course
OK, I'm going to apologies in advance if the following is either to simple or too complicated. If you are going to use C# you should really look into object oriented design (lots of references around), but only when and if you are comfortable with control flow logic (loops and descision statements etc). Getting you head around this will save a lot of work in the long run, but it's daunting as you start out (or it was for me anyway )
You should condisder breaking some of your code down further into classes. A class is a way of gathering properties (e.g. Size) and methods (e.g. Add/Remove Toppings) into one logical place (often representing something in the real world). This is known as encapuslation and prevents any unwanted side-effects from other things happening if you do it correctly. e.g. in your example a mistake is causing the total to be incorrect.
For example:
If you create a class called Topping, you could create several of these. The topping might have a property called Description (e.g. Description = "Ham") and a set of prices for each size (there are several way to do this, e.g. have a property for each size, which is less good or consider using a Dictionary )
Now you could have Pizza class, this could have a List of Toppings, a Size (and a list of pizza-base prices for each size, just like the topping) an a calculate cost method. To calculate the cost, you take the pizza-base cost for the current size, and for each topping add it's cost according to the pizza size.
A good initial way to work out which classes, properties and methods you need is to write down what you want to achieve, nouns indicate classes or properties, verbs indicate a method is required.
e.g.
A pizza can come in different sizes and have several toppings added or removed as required. Calculate the cost of the pizza and show to the customer.
Note that you'll see the classes Pizza and Topping I sugested highlighted as well as the size property. Also highlighted are "Add[Topping]" and "Remove[Topping]", I haven't put these on the pizza class directly, though you could. I have suggested you create a property called Toppings which is a List of toppings (List<Topping> google up List<T> for more advice). The list itself has an Add & Remove methods, so you don't have to add them.
This seems like a chore, but 99% of the time it works easier. For example you could now add new types of topping easily or add stuff to save to a database. If you implement it well , new pizza sizes should be easy and the code you write should be more readable, robust & easy to adapt to new requirements (all of which are important when programming)!
Good luck with your course, and I hope you enjoy it. I'm jelous, I wish I could unlearn the stuff I have done, just so I could re-learn it! On the up side I suppose there are lots of cool new things being done in IT to find out about all the time. I am such a geek!
CCC solved so far: 2 (including a Hard One!)
|
|
|
|
|