我現在有一個標準的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();
}
這讓我傳遞值進行的跨向其中輸入manually.However我希望能夠到數據庫從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>
你有什麼已經嘗試過? Linq2Xml?用XmlDocument解析?哪些問題你在閱讀文件遇到過嗎? – 2012-07-25 13:35:11