locked
Save to SQL Using WCF from XAML Form RRS feed

  • Question

  • Hi All,

    Some help needed please as am new to WCF services Silverlight.

    I have created a silverlight project and follow various blogs and videos to add the Entity Model and Data service, this all works fine I also added the services references etc and can browes to data servers in IE.

    So I then created a XAML form with the following text boxes and would like to save the data from the form to SQL

            <TextBox Grid.Column="2" Grid.Row="4" Height="28" HorizontalAlignment="Right" Name="strUsername" VerticalAlignment="Top" Width="250" Margin="0,4,2,0" BorderBrush="#FFA5CB0E" />
            <TextBox Grid.Column="2" Grid.Row="5" Height="28" HorizontalAlignment="Right" Name="strFirstname" VerticalAlignment="Top" Width="250" Margin="0,4,2,0" BorderBrush="#FFA5CB0E" />
            <TextBox Grid.Column="2" Grid.Row="6" Height="28" HorizontalAlignment="Right" Name="strSurname" VerticalAlignment="Top" Width="250" Margin="0,4,2,0" BorderBrush="#FFA5CB0E" />
            <TextBox Grid.Column="2" Grid.Row="7" Height="28" HorizontalAlignment="Right" Name="strEmail" VerticalAlignment="Top" Width="250" Margin="0,4,2,0" BorderBrush="#FFA5CB0E" />

    The my form code:

                MyEntities ctx = new MyEntities(new Uri("http://localhost:1351/MyDataSVC.svc/", UriKind.Absolute));

                var NewProfile = new UserProfile();
                NewProfile.username = strUsername.ToString();
                NewProfile.name_first = strFirstname.ToString();
                NewProfile.name_last = strSurname.ToString();
                NewProfile.email_id = strEmail.ToString();

    Now this is where I really need the help, what's the code I need here to insert the data to SQL please???? I've tried various samples and none of them works.

    Many thanks.



    Microsoft SharePoint 2007, Microsoft SQL 2008

    Monday, September 24, 2012 12:41 PM

All replies

  • Hi,

    On your MyEntities class there should be a method called something like AddToUserProfiles which will take a single parameter of type UserProfile. Call that and pass in the newly create instance. After that call ctx.SaveChanges which will send your updates to the service.

    Thanks,


    Vitek Karas [MSFT]

    Monday, September 24, 2012 4:10 PM
    Moderator