嗨全部 一直以來,因爲我試圖figuare出如何更新我的SQLServer表中的XML列。確定了清晰的認識我想1. 每一位ID增加好吧,這是我的表名稱爲設置(SettingId INT PK,名稱爲nvarchar(100),XmlSetting XML)我想更新我的數據庫中的xml列使用C#
//我data.xml中
<setting>
<a id=1/>
<b id=2/>
<c id=22>
</setting>
遞增這個代碼我的C#代碼如下
XmlDocument xdoc = new XmlDocument();
private void SetAttribute(System.Xml.XmlNode node)//this code is running in the memory
{
System.Xml.XmlElement element = node as System.Xml.XmlElement;
if (element != null)
{
int attributeCount = element.Attributes.Count;
for (int i = 0; i < attributeCount; i++)
{
System.Xml.XmlAttribute attribute = element.Attributes[i];
if (string.Compare(attribute.Name, "Id", System.StringComparison.OrdinalIgnoreCase) == 0)
{
int value;
if (int.TryParse(attribute.Value, out value))
{
attribute.Value = (value + 1).ToString();
}
else
{
attribute.Value = "1";
}
}
}
int childNodeCount = element.ChildNodes.Count;
for (int i = 0; i < childNodeCount; i++)
{
SetAttribute(element.ChildNodes[i]);
}
}
}
public void EditXmlFile()
{
xdoc.Load(FILE_NAME);
SetAttribute(xdoc.FirstChild);
return;
}
所有我所要求的是更新的代碼到我的數據庫表設置
private void btnUpdate_Click(object sender, EventArgs e)
{
SqlConnection cnn = new SqlConnection("connectionPath");
SqlCommand cmd=new SqlCommand("Update Setting set [email protected] where settingId=5",cnn);
cmd.Parameters.AddWithValue("@SettingXml","")//this where I am stacked because I am failing
try
{
cnn.Open();
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
lblmsg.Text = "Error updating Xml " + ex.Message;
}
}
如何更新我更新與上述功能這SettingXml列,因爲我想在1
老實說,你的格式是相當混亂... – 2011-03-29 15:37:24
這是他有史以來第二個問題。削減他一些鬆懈。 – 2011-03-29 15:41:16