Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8677143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:22:49+00:00 2026-06-12T20:22:49+00:00

Easy-to-follow examples of CRD (Create, Read, Delete) appear in MSDN here There is a

  • 0

Easy-to-follow examples of CRD (Create, Read, Delete) appear in MSDN here

There is a nice link on the page to a script to make a test database, and I did so, and easily got all the examples working for CRD.

There are even handy sub-headers on the page for CRD:

(Create rows) http://msdn.microsoft.com/en-us/library/hh361033.aspx#BKMK_UpdateDB

(Read rows) http://msdn.microsoft.com/en-us/library/hh361033.aspx#BKMK_QueryData

(Delete rows) http://msdn.microsoft.com/en-us/library/hh361033.aspx#BKMK_DeleteRows

The one called BKMK_UpdateDB doesn’t do the U in CRUD. Its name says Update, but it really does the C in CRUD.

If I missed where on this page the U in CRUD is shown, just shoot me now and quit reading…

Could one of the guru’s here please provide a little help?

To lighten the junk-work-load for the guru’s: Below is the code pretty much as it appears on the MSDN web page.

Just run the test-database-create .sql script referred to on the web page, edit the SqlDataConnection string in the code below for your server and database-name, it should run fine.

Note that the only change I made to the query is to get just one row to update. Now exactly one row is returned. Seems more important to see the simple case of one row changed. At least that before showing multiple-changes-at-once.

Can a guru please change the last 4 lines into the recommended F#-Type-Provider way to make a change to the data returned by the query, and write that changed row out to the database?

For example, change row.TestData1 from 10 to 11 and write it to the db.

Summing up: The MSDN page makes it easy for us F#-Type-Provider newbies to do the CRD in CRUD.

Can a guru please fill us newbies in on the right/easy F#-Type-Provider way to do the U in CRUD?

Many thanks!

#r "System.Data.dll"
#r "FSharp.Data.TypeProviders.dll"
#r "System.Data.Linq.dll"
open System
open System.Data
open System.Data.Linq
open Microsoft.FSharp.Data.TypeProviders
open Microsoft.FSharp.Linq

type dbSchema = SqlDataConnection<"Data Source= --yourServer\yourInstance--;Initial Catalog= --YourTestDatabaseFromTheScript--;Integrated Security=SSPI;">
let db = dbSchema.GetDataContext()
let table1 = db.Table1

query { for row in db.Table1 do
        where (row.TestData1 <= 10)
        select row } 
    |> Seq.iter (fun row -> printfn "%d %s" row.TestData1 row.Name)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:22:50+00:00Added an answer on June 12, 2026 at 8:22 pm

    I haven’t had a chance to try the new query expressions yet — so this is just a guess:

    query { for row in db.Table1 do
        where (row.TestData1 <= 10)
        select row } 
        |> Seq.iter (fun row ->
            // Update the row with some new value.
            row.TestData1 <- row.TestData1 + 1)
    
    // Now, call .SubmitChanges() to execute the SQL and update the database
    try
        db.DataContext.SubmitChanges()
        printfn "Successfully updated the rows."
    with
       | exn -> printfn "Exception:\n%s" exn.Message
    

    The code on this page gives another example of how this works, albeit in C#. Basically, the F# query expression is (in this case) simply wrapping Linq-to-SQL; so if the code I posted doesn’t work, you should take a look at some of the new .NET 4.5 examples of Linq-to-SQL with C#.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As a follow up to this question: Is there an easy way to pickle
Could I get very easy to follow code examples on the following: Use browser
Some easy points for somebody here, take the following table of data: EventCode ProcessId
the easy part is to create the image and the mask for it: //
I have been trying to follow the few tutorials on how to create a
Two quick questions here... How can I use this example http://try.sencha.com/touch/2.0.0/examples/list-search/ of a searchable
I have been trying to follow some WCF Data Services examples and have the
I like to keep my unit tests pretty simple and easy to follow. I
I'm wondering if there's any relatively easy way to extend NHibernate to support F#'s
Here's some easy reputation for someone. The scenario I have a table that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.