【发布时间】:2017-03-02 10:16:17
【问题描述】:
我创建了一个可以创建连接字符串和编辑连接字符串的应用程序。
doc.Load(Path.Combine(path, SelectConfigComboBox.SelectedItem.ToString(), "app.config"));
XmlNode xNode = doc.CreateNode(XmlNodeType.Element, "add", "");
XmlAttribute xName = doc.CreateAttribute("name");
XmlAttribute xconnectionString = doc.CreateAttribute("connectionString");
xName.Value = NewKeyTextBox.Text;
xconnectionString.Value = string.Format("data source={0};persist security info={1};initial catalog={2};USER ID={3};password={4}", NewValueTextBox.Text, SecurityInfocomboBox.Text, CatalogcomboBox.Text, UserIDtextBox.Text, PasswordtextBox.Text);
xNode.Attributes.Append(xName);
xNode.Attributes.Append(xconnectionString);
doc.GetElementsByTagName("connectionStrings")[0].InsertAfter(xNode,
doc.GetElementsByTagName("connectionStrings")[0].LastChild);
doc.Save(Path.Combine(path, SelectConfigComboBox.SelectedItem.ToString(), "app.config"));
通过这段代码,我输入了一个新的连接字符串。当我想编辑连接字符串时,它将添加一个新的而不删除另一个。如何在添加新的之前删除旧的?
【问题讨论】:
标签: c# winforms connection-string