I currently have this method in a standard web service:
[WebMethod]
public void addGame(int GamePlayID, int @ParticipantID, int @GameVersionID, string Start, string End,string success)
{
SqlConnection oConn = new SqlConnection();
oConn.ConnectionString = @"Data Source=SNICKERS\SQLEXPRESS;Initial Catalog=VerveDatabase;Integrated Security=True";
oConn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = oConn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "addGamePlay";
cmd.Parameters.Add(new SqlParameter("@GamePlayID", SqlDbType.Int));
cmd.Parameters["@GamePlayID"].Value = GamePlayID;
cmd.Parameters.Add(new SqlParameter("@ParticipantID", SqlDbType.Int));
cmd.Parameters["@ParticipantID"].Value = @ParticipantID;
cmd.Parameters.Add(new SqlParameter("@GameVersionID", SqlDbType.Int));
cmd.Parameters["@GameVersionID"].Value = @GameVersionID;
cmd.Parameters.Add(new SqlParameter("@Start", SqlDbType.Time));
cmd.Parameters["@Start"].Value = Start;
cmd.Parameters.Add(new SqlParameter("@End", SqlDbType.Time));
cmd.Parameters["@End"].Value = End;
cmd.Parameters.Add(new SqlParameter("@success", SqlDbType.VarChar, 10));
cmd.Parameters["@success"].Value = success;
cmd.ExecuteNonQuery();
}
This allows me to pass values accross to the database which are entered manually.However I want to be able to load the data from an XML document. How do I get data from this XML document to fill the variables in this method. Here is the XML document:
<?xml version="1.0" encoding="UTF-8"?>
<anyType xmlns="http://tempuri.org/" xmlns:d1p1="http://www.w3.org/2001/XMLSchema-instance" d1p1:type="q1:string" xmlns:q1="http://www.w3.org/2001/XMLSchema">
<NewDataSet>
<Game>
<GamePlayID>1</GamePlayID>
<ParticipantID>1</ParticipantID>
<GameVersionID>1</GameVersionID>
<Start-Time>PT0S</Start-Time>
<End-Time>PT5H</End-Time>
<Success>true </Success>
</Game>
</NewDataSet>
</anyType>
I don’t quite understand why I got down voted as this was a genuine question however I thought I would outline how I managed to over come the problem. As my paticular XML document only contains one node I used the “selectSingleNode” function on xmlDocument to pick the data I wanted and assigned them to variables ready to insert into my database via SQL proc.