HomeCommunityControl GalleryData & XMLBetter DataReader

Better DataReader



Submit a Review

353 Downloads

9,714 Views


Description

Use Better DataReader in projects where you used a DataReader but are having problems because iterating through the data is taking longer than you expected. This control is generic in regards to what data provider you use, so you can isolate your data access layer from you business layer. This free implementation replaces .Net's DataReader with a custom one that does not require an open connection while iterating through it either backwards or forwards. Also includes other custom features like Null2Value that handles DBNulls.

Syntax Example

Me.ComboBox1.Items.Clear() Dim Cn As New OleDbConnection("Provider=Microsoft.Jet .....) Dim Cmd As New OleDbCommand("Select * from step", Cn) Dim Dr As New AspCreationsControls.BetterDataReader Cn.Open() 'Use the SetReader property here in place of Dr = Cmd.ExecuteReader Dr.SetReader = Cmd.ExecuteReader Cn.Close() ' You can now close the data connection Do While Dr.Read Me.ComboBox1.Items.Add(Dr.GetString("MY_ESTRATE")) 'You can use ordinal or the column name. 'Converts a double to a string without DBNull errors. If you want the actual item value including any DBNulls then use Dr.Item("MY_ESTRATE") Loop 'Dr.Close() 'This is not required because the reader closes automatically after [Dr.SetReader = Cmd.ExecuteReader] is called. 'It purpose is to support existing implementation but does nothing '*********Another Usage************************ Dim i as integer 'You can iterate backwards For i=Dr.Count-1 to 0 Step -1 Dr.CurrentIndex = i Debug.WriteLine(Dr.Null2Value(Dr.Item("MY_ESTRATE"), "No Esitmated-Rate Found")) 'This function returns the string "No Esitmated-Rate Found" if the value is DBNull or 'if not null then the object is casted as what ever the second argument is, 'in this case it is System.String. Next

Reviews

Submit a review