Well, I stepped in it now. I’m converting a program from Access vba to C# so I can run it independently (that’s another story…) The program reads an Excel file and then validates each row and column to be sure the data is valid (numeric, etc) and then looks up various data fields to create a transaction table on SQL Server. The transaction table is never re-validated, so it must be correct on the first try.
I’m used to procedural languages (though I have a passable knowledge of T-SQL), but now (VS2010) it appears I need to use either “LINQ to SQL” or “Entity Data Model” to get the data out of SQL Server (2005). Historically, I’ve used DAO or ADO recordsets. I need to retrieve multiple columns at a time, though by and large, I won’t be updating the tables. I can make the updates using SQL Server stored procedures (and presumably ADO?)
Although I’ve begun work using Windows Forms, I’m likely to shift it over to a console app before I finish.
What do you guys recommend? My book (C# 4.0 Griffiths, Adams and Liberty) has been talking about Entity Data Model mostly. But since I’m using SQL Server (2005) exclusively, isn’t “Linq to SQL” more appropriate? Any references to help me get started? Here’s an example “method” (in vba…) that I’m using now that’s pretty standalone that I’m using for my first attempt:
Function ValidateOverride(LaborRateID As Variant) As Long
If IsNull(LaborRateID) = True Or IsNumeric(LaborRateID) = False Then
ValidateOverride = 0
Exit Function
End If
Dim rstOverrideLaborRates As DAO.Recordset2
Set rstOverrideLaborRates = CurrentDb.OpenRecordset("SELECT * FROM tblStaffAugLaborRates WHERE ID=" & LaborRateID, dbOpenDynaset, dbSeeChanges + dbFailOnError)
If rstOverrideLaborRates.EOF Then
HandleMessages "Row Rejected -- Invalid Override Labor Rate"
ValidateOverride = 0
Else
ValidateOverride = LaborRateID
If (dtCurrentWorkDate < rstOverrideLaborRates!EffectiveDate) Or (dtCurrentWorkDate > rstOverrideLaborRates!ExpirationDate) Then
HandleMessages "Row Rejected -- Override Labor Rate is not within its valid dates"
ValidateOverride = 0
End If
If rstOverrideLaborRates!VendorID <> lngCurrentVendorID Then
HandleMessages "Row Rejected -- Override Labor Rate is not valid for this vendor"
ValidateOverride = 0
End If
End If
rstOverrideLaborRates.Close
Set rstOverrideLaborRates = Nothing
End Function
Are u sure u want to rewrite your program? What else does it beside parsing the excel? I would recommend u into using SSIS, i’ve writen some import/export routines and a conversion using SSIS, it’s extreme fast and they are improving it even more. It’s really really good!
I don’t think u need, but if u have the need for a GUI u can use start up SSIS package and be notified what’s happening in the process.
PS: Logging is implemented out of the box