Switch to fluid Switch to wfix Switch to fixed

StackPanel

dynamic rants = new Stack();

Update database table using Linq to Sql

Posted by Vin on Jun-20-2008
  1. First things first, table needs to have a primary key defined
  2. The dbml file’s table needs to reflect the Primary key, if not set the Primary Key flag of the column to true, and auto-sync property to “Never”

Code snippet - Update an Xml datatype column with an Xml file

private void btnUpdate_Click(object sender, RoutedEventArgs e)
{
string sqlConnection = @"Data Source=servername;Initial Catalog=dbname;Integrated Security=True";
string xmlPath = @"C:\MyPath\";
using (StreamReader reader = new StreamReader(xmlPath + "MyXmlFile.myxml"))
{
string scalarXml = reader.ReadToEnd();
MyDataDataContext db = new MyDataDataContext(sqlConnection);
MyFile myFile = db.MyFiles.Single(f => f.FileName == "MyXmlFileType");
myFile.XmlContent = XElement.Parse(scalarXml);
myFile.ModifiedOn = DateTime.Now;
db.SubmitChanges();
System.Diagnostics.Debug.WriteLine(db.Log);

}
}