Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now
error:System.InvalidCastException: 'Specified cast is not valid.'
csv data:
datetime Miliseconds MachineAutoStartStop pressure
25/10/2022 0:00 655 1 0.382796
25/10/2022 0:00 899 1 0.382796
25/10/2022 10:31 37 1 0.382796
25/10/2022 10:31 38 1 0.382796
25/10/2022 10:31 787 1 0.382796
error line: cmd.Parameters.AddWithValue("@DateTime", (DateTime)importRow["DateTime"]);
code:
using (SqlConnection conn =New SqlConnection(@"Data Source=BL03\SQLEXPRESS; Initial Catalog=HDB; User Id=sa; Password=00")) { conn.Open(); foreach (DataRow importRow in S2P5.Rows) { SqlCommand cmd = new SqlCommand ("INSERT INTO S2P5 (DateTime, Miliseconds, MachineAutoStartStop, Pressure)" + "VALUES (@DateTime, @Miliseconds, @MachineAutoStartStop, @Pressure)", conn); cmd.Parameters.AddWithValue("@DateTime", (DateTime)importRow["DateTime"]); cmd.Parameters.AddWithValue("@Miliseconds", importRow["Miliseconds"]); cmd.Parameters.AddWithValue("@MachineAutoStartStop", importRow["MachineAutoStartStop"]); cmd.Parameters.AddWithValue("@Pressure", importRow["Pressure"]); cmd.ExecuteNonQuery(); }
You might have wanted to post this in a different forum?
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.