0

I would like to insert data from xml files to sql database. In my xml files are a lot of diffrent rows. But many rows contain empty double values. When i try to add this to my database i get an error.

Here is a short cut from my database insert:

   Table<Step> step = Accessor.GetStepTable();
                Step stp = new Step();

                stp.Angle1Actual = stepData.Columns.Contains("Angle1Actual") ? double.Parse(stepData.Rows[index][Array.IndexOf(argsStep, "Angle1Actual")].ToString()) : DBNull.Value;

                step.InsertOnSubmit(stp);
                step.Context.SubmitChanges();

The problem is the DBNull is diffrent type

2 Answers2

0

Try using double.TryParse instead of double.Parse. It returns boolean value if the operation was successfull.
Reference: https://msdn.microsoft.com/en-us/library/system.double.tryparse(v=vs.110).aspx

Piotshe
  • 59
  • 7
0

DBNull is not "null". It is a type, a class in the framework.

Here is an SO question: What is the best way to deal with DBNull's

Community
  • 1
  • 1
radarbob
  • 4,964
  • 2
  • 23
  • 36