title: Silverlight 2 - Adding database records using WCF
body: <p>I'm creating a simple Silverlight 2 application - a guestbook. I'm using MSSQL as the data source, I've managed to load the data but I can't find out how to add new rows (messages) to the database.</p>
  
  <p>I crawled all the internet but didn't find any working solution. The SCMEssages table has four columns - MessageID, MessageDate, MessageAuthor and MessageText. Right now I have the following code in Service1 class (which implements IService1 interface) (not working though):</p>
  
  <pre><code>    public void SaveMessage(SCMessage message)
      {
          DataClasses1DataContext db=new DataClasses1DataContext();
          db.GetTable&lt;SCMessage&gt;().Attach(message);
          db.SubmitChanges();
      }
  </code></pre>
  
  <p>In the main class I'm simply calling this method:</p>
  
  <pre><code>    private void SendBtn_Click(object sender, RoutedEventArgs e)
      {
          SCMessage sm = new SCMessage
                             {
                                 MessageAuthor = NameTB.Text,
                                 MessageDate = DateTime.Now,
                                 MessageText = TextTB.Text
                             };
          newMessages.Add(sm);
  
          ServiceReference1.Service1Client client = new Service1Client();
          client.SaveMessageAsync(sm);
      }
  </code></pre>
  
  <p>Could anybody help me? Thanks for any suggestions!</p>