1

I am new to programming and F# is my first language.

I want to load data into a SQL Server database using F# code. Here is the table that is supposed to store my data:

CREATE TABLE [dbo].[Scores](
 [EventName] [nvarchar](100) NOT NULL,
 [Winner] [nvarchar](50) NOT NULL,
 [Loser] [nvarchar](50) NOT NULL,
 [Score1] [nvarchar](10) NOT NULL,
 [Score2] [nvarchar](10) NOT NULL,
 [Score3] [nvarchar](10) NOT NULL
) ON [PRIMARY]

Score1, Score2 and Score3 are supposed to contain judges' scores, which might be unavailable sometimes.

Here is my F# code for loading the data:

 new dbSchema.ServiceTypes.Fights(EventName = fightSummary.event,
 Winner = fightSummary.winner.Value,
 Loser = fightSummary.loser.Value,
 Score1 = if judgesScoresExist then
 fightSummary.judgesScores.Value.[0]
 else
 "None",
 Score2 = if judgesScoresExist then
 fightSummary.judgesScores.Value.[1]
 else 
 "None",
 Score3 = if judgesScoresExist then
 fightSummary.judgesScores.Value.[2]
 else "None")

When I try to run the F# code above, I receive the following error message:

This expression was expected to have type string but here has type 'a * 'b

Apparently, the compiler interprets the part

"None", Score2 = ...

as a tuple.

I tried searching online for a solution, but have yet to find one.

What changes should I make so that I can load my data into SQL Server?

asked May 12, 2015 at 13:11
0

1 Answer 1

3

Put if then else expressions in parenthesis:

let v = new Fights(EventName = fightSummary.event,
 Winner = fightSummary.winner.Value,
 Loser = fightSummary.loser.Value,
 Score1 = (if judgesScoresExist then
 fightSummary.judgesScores.Value.[0]
 else
 "None"),
 ...) // etc.
ildjarn
63.2k9 gold badges133 silver badges219 bronze badges
answered May 12, 2015 at 13:35
1
  • Now I feel stupid for not having thought of it! Thank you, Petr! :-) Commented May 12, 2015 at 13:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.