[thelist] connecting to a database: .NET 1.1 vs. 2.0

Joel D Canfield joel at streamliine.com
Mon Aug 6 11:06:54 CDT 2007

The gent I'm building some baby .NET apps for knows just enough about
.NET to ask some interesting questions (he's a good friend and a smart
guy; don't wanna give the wrong impression.)

He's of the belief that with 2.0, database connections can be made
without coding, and that the whole 'connect to a db and get data' thing
is almost magic.

What I find is this:


a long, tedious journey through a GUI using the mouse. I'd rather eat

How, exactly, would you create a database connection in 2.0 in
codebehind? This is what I'm currently doing in 1.1 to create a select
form element listing all the items in particular table; suggestions for
tidying this up (other than 'use a stored procedure, ya lazy bum!' which
I already know) are more than welcome:
Sub List_Employees()
	Dim cnxJoel as SqlConnection
	Dim strQuery as String
	Dim cmdGetEmpList as SqlCommand
	Dim dtrEmpList as SqlDataReader

	cnxJoel = New
	strQuery = "select id, (LastName + ', ' + FirstName) as Fullname
from employees order by LastName, FirstName"
		cmdGetEmpList = New SqlCommand(strQuery, cnxJoel)
		dtrEmpList = cmdGetEmpList.ExecuteReader()
			dropEmpList.DataSource = dtrEmpList
			dropEmpList.DataValueField = "id"
			dropEmpList.DataTextField = "Fullname"
		dropEmpList.Items.Insert(0, New ListItem("Select the
employee to change","blank"))
End Sub


More information about the thelist mailing list