|
Using databases in C# can be daunting for developers moving from VB6, VBA, or
Access. From the differences in the .NET syntax to the curly braces and semicolons,
just looking at the code in C# for the first time can be intimidating. As you start to use
C#, the small changes you need to make become easier and the code starts to flow
nicely. However, you will likely find that many ways of working with data and databases
that were easy in VB6 and VBA can be challenging when attempted for the first time in
C#.
When you were programming in Classic VB, you could count on a good solid example
of how to use a particular method, and it would be in context. For instance, if you were
looking at a connection string example, it would likely include how to connect to the
database, and it would probably also include a recordset or query. In C# and the
other .NET languages, you will find fewer full examples and more examples that simply
show the syntax. Or worse, they’ll show the other objects in the example, but won’t
explain how to create those objects or explain where the object needs to be declared
(at the form level or at the procedure level).
What led to this book was a challenge that I faced while doing something that I thought
should have been very simple. I wanted to create a form with a datagrid that would
load a table or query at runtime with the ability to filter, sort, and edit the records. I
could do this task with Classic VB in a few minutes and in even less time with VBA
inside of Access. With C#, there were pieces that were very simple, but only simple
when building the connection to a single database and a single table that you define at
design time. Getting code to change the datasource at runtime or connecting to a different
table when your database schema changes was significantly more challenging.
In addition, the help available online from within Visual Studio or even from an Internet
search wasn’t very complete. It isn’t enough to know the method that you need to call;
you need to understand where the variables are declared, the changes that are needed
to the properties on the datagrid, the “using” references that are required, etc. Once
you see it, the code is very clear, but it is less than straightforward when you are starting
out. |