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.
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):
public void SaveMessage(SCMessage message)
{
DataClasses1DataContext db=new DataClasses1DataContext();
db.GetTable<SCMessage>().Attach(message);
db.SubmitChanges();
}
In the main class I'm simply calling this method:
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);
}
Could anybody help me? Thanks for any suggestions!