我有一个读取 xml WebResponse 的数据集,然后我从该数据集中提取和合并表我如何将 7 个硬编码标签添加到合并表中以显示在数据网格中,标签始终是相同的值,并且顺序将始终是相同的。
我想为了方便起见,我想在表格中添加 7 行标题?与数据网格一起显示。
我试过的
WebRequest req = WebRequest.Create(m_uri);
WebResponse rsp;
req.Method = "POST";
req.ContentType = "text/xml";
StreamWriter writer = new StreamWriter(req.GetRequestStream());
writer.WriteLine(buildXml().ToString());
writer.Close();
rsp = req.GetResponse();
//Get the Posted Data
StreamReader reader = new StreamReader(rsp.GetResponseStream());
string rawXml = reader.ReadToEnd();
XmlDocument xml = new XmlDocument();
xml.LoadXml(rawXml);
//Use XPath to Navigate the Document
int status = Convert.ToInt32(xml.SelectSingleNode(@"/RatingServiceSelectionResponse/Response/ResponseStatusCode").InnerText);
if (status == 1)
{
StringReader srxml = new StringReader(rawXml);
DataSet dsAuthors = new DataSet("RatedShipment");
dsAuthors.ReadXml(srxml);
dsAuthors.EnforceConstraints = false;
DataTable Shipment = dsAuthors.Tables[2];
DataTable TotalCharges = dsAuthors.Tables[8];
DataTable table = new DataTable("UPS Service");
Shipment.Merge(TotalCharges);
Shipment.Columns.Remove("RatedShipmentWarning");
Shipment.Columns.Remove("CurrencyCode");
Shipment.Rows.RemoveAt(7);
DataColumn UPSService = new DataColumn();
UPSService.DataType = typeof(string);
UPSService.ColumnName = "UPS Service";
Shipment.Columns.Add(UPSService);
Shipment.Rows[0].Cells[0].Value = "UPS Ground";
Shipment.Rows[1].Cells[0].Value = "UPS Three Day";
Shipment.Rows[2].Cells[0].Value = "UPS Second Day A.M.";
Shipment.Rows[3].Cells[0].Value = "UPS Second Day";
Shipment.Rows[6].Cells[0].Value = "UPS Next Day Air Saver";
Shipment.Rows[4].Cells[0].Value = "UPS Next Day Air Early A.M.";
Shipment.Rows[5].Cells[0].Value = "UPS Next Day Air";
dataGridView1.DataSource = Shipment;
}
else
{
MessageBox.Show("Unable To Process: Please Check All Fields Are Entered");
}
但是行后的单元格不正确。