Code reuse
-
I guess the programmer of the snippet below found a function to fill a DropDownList and adjusted it just enough to fill a TextBox...
Private Sub ShowName(ByVal id As String)
Dim daNames As New SqlDataAdapter("SELECT ID, NAME FROM TBL\_NAMES", ConnectionString) Dim dsNames As New DataSet("NAMES") daNames.Fill(dsNames, "NAMES") Dim drNames As DataRow = dsNames.Tables(0).NewRow drNames("ID") = -1 drNames("NAME") = "" dsNames.Tables(0).Rows.InsertAt(drNames, 0) If dsNames.Tables("NAMES").Rows.Count > 0 Then Try Dim drs() As DataRow = dsNames.Tables(0).Select("ID = " & id) txtName.Text = drs(0).Item("NAME").ToString Catch e As Exception ' End Try Else txtName.Text = "" End If
End Sub
-
I guess the programmer of the snippet below found a function to fill a DropDownList and adjusted it just enough to fill a TextBox...
Private Sub ShowName(ByVal id As String)
Dim daNames As New SqlDataAdapter("SELECT ID, NAME FROM TBL\_NAMES", ConnectionString) Dim dsNames As New DataSet("NAMES") daNames.Fill(dsNames, "NAMES") Dim drNames As DataRow = dsNames.Tables(0).NewRow drNames("ID") = -1 drNames("NAME") = "" dsNames.Tables(0).Rows.InsertAt(drNames, 0) If dsNames.Tables("NAMES").Rows.Count > 0 Then Try Dim drs() As DataRow = dsNames.Tables(0).Select("ID = " & id) txtName.Text = drs(0).Item("NAME").ToString Catch e As Exception ' End Try Else txtName.Text = "" End If
End Sub
DataAdapter and DataSet are so powerful they can be used to do anything... poorly.
-
DataAdapter and DataSet are so powerful they can be used to do anything... poorly.
Cool! Can i quote that? I had a boss who used those as his all powerful silver bullet, and many a wtf ensued.
------------------------------- Carrier Bags - 21st Century Tumbleweed.
-
Cool! Can i quote that? I had a boss who used those as his all powerful silver bullet, and many a wtf ensued.
------------------------------- Carrier Bags - 21st Century Tumbleweed.
Ummm yeah.