我目前在标准 Web 服务中有这种方法:
[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();
}
这允许我将值传递给手动输入的数据库。但是我希望能够从 XML 文档加载数据。如何从此 XML 文档中获取数据以填充此方法中的变量。这是 XML 文档:
<?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>