nbk5533

I'm looking to see if anyone has code that would display the Progress Bar when loading data to a DataSet from a Database. The progress bar doesn't run until after the DataSet is loaded. I've made an attempt to create write the code that would allow to look each Record that is being added but the code still fails to update the Progress Bar accurately.

Much appreciated,

Wallace



Re: Windows Forms Data Controls and Databinding Implement a Progress Bar with a DataSet using VB.NET

Ken Tucker



This is a kind of workaround for filling a dataset with a progressbar.

Used is the NorthWind SQL database as sample database, while the sample needs a datagrid and a progressbar on a form.

Be aware that this sample uses a show in the load event. It is better not to do that. However in this case to keep the sample simple, because otherwise a button was needed, which could confuse.



Re: Windows Forms Data Controls and Databinding Implement a Progress Bar with a DataSet using VB.NET

Cael Z

If coding like the post about ,there will be a performance penalty when working large amounts of data.






Re: Windows Forms Data Controls and Databinding Implement a Progress Bar with a DataSet using VB.NET

nbk5533

Cael,

I've implemented the code but again, the Progress Bar doesn't run until after the data is loaded in the DataSet. I have Stepped into the code and it appears to be looping on a particular column within the DataSet/DataTable. It takes longer for the code to update the DataGridView. I'm going to step back until I can get caught up on a few other developments I need to complete and provide some additional information. If there are any other resources I would appreciate the help.

Thanks again,

Wally





Re: Windows Forms Data Controls and Databinding Implement a Progress Bar with a DataSet using VB.NET

timvw

Imho it's a whole lot easier to set the Style of the ProgressBar to Marquee and let the control update itself...





Re: Windows Forms Data Controls and Databinding Implement a Progress Bar with a DataSet using VB.NET

nbk5533

Here's my code:

I am clicking on a Button control named Load Data. The error I receive is "InvalidCastException was unhandled. Conversion from string "00:13:21Big Smile1:4B:80 " to type 'Integer' is not valid." In the bold area below, I've changed the Data Type to String and it also gave me a error. The current DataType I'm using in our Database (platform_validation_tool) is "nchar". The Data in our datbase is primarly, alpha, numeric, comma's, colons and semicolons. Not sure what other datatypes I could use.

Second, if I set the ProgressBar1.Maximum = 100, no errors, but, the progress bar progresses quickly, stops about 7/8 of the way and then my application just hangs. Belows it the code that connect to the Database, loop through each row in the table, and do some magic with the ProgressBar control but no success.

Any help would be appreciated.

Class Form1

Private Sub btnLoadData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoadData.Click

'AllTablesDataSet1.Clear()

Dim PvtSqlConnection As New SqlClient.SqlConnection("Initial Catalog=platform_validation_tool;Data Source=B001279AE624B;Connection Timeout=25")

Dim SqlCmd As New SqlClient.SqlCommand("dbo.uspPvtSelectCommand", PvtSqlConnection)

PvtSqlConnection.Open()

ProgressBar1.Maximum = CType(SqlCmd.ExecuteScalar, Integer)

ProgressBar1.Step = 1

ProgressBar1.Minimum = 0

SqlCmd.CommandText = "dbo.uspPvtSelectCommand"

Dim rdr As SqlClient.SqlDataReader = SqlCmd.ExecuteReader

Dim ds As DataSet = AllTablesDataSet1

Dim dt As DataTable = AllTablesDataSet1.uspPvtSelectCommand

Show()

While rdr.Read

If dt Is Nothing Then

dt = AllTablesDataSet1.uspPvtSelectCommand

Dim dtSchema As DataTable

dtSchema = rdr.GetSchemaTable

For Each drschema As DataRow In dtSchema.Rows

dt.Columns.Add(drschema("ColumnName").ToString, _

Type.GetType(drschema("DataType").ToString))

Next

End If

ProgressBar1.PerformStep()

Dim dr As DataRow = dt.NewRow

Dim tempObject(dt.Columns.Count - 1) As Object

rdr.GetValues(tempObject) ' did not go in one time

dr.ItemArray = tempObject

dt.Rows.Add(dr)

End While

ds.Tables.Add()

DataGridView1.DataSource = ds.Tables(0)

rdr.Close()

PvtSqlConnection.Dispose()

'SqlDataAdapterToPVT.Fill(AllTablesDataSet1.uspPvtSelectCommand)

End Sub





Re: Windows Forms Data Controls and Databinding Implement a Progress Bar with a DataSet using VB.NET

Ken Tucker

Could you post the code for the dbo.uspPvtSelectCommand stored procedure




Re: Windows Forms Data Controls and Databinding Implement a Progress Bar with a DataSet using VB.NET

nbk5533

I sure can. Here's the stored procedure:

set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

go

ALTER PROCEDURE [dbo].[uspPvtSelectCommand]

AS

SET NOCOUNT ON;

SELECT main.MAC, main.CREATED, main.MODIFIED, hardware.MANUFACTURER, hardware.MODEL, hardware.CHASSIS, hardware.SERIAL_NUMBER, hardware.PROCESSOR,

hardware.HARD_DRIVE, hardware.HARD_DRIVE_SIZE, hardware.MEMORY, network.WORKSTATION_NAME, network.IP_ADDRESS,

network.USER_NAME, network.OPERATING_SYSTEM, network.SERVICE_PACK, network.BAND_VERSION, network.WORKSTATION_OU,

network.WORKSTATION_OWNER, software.MAC AS Expr1, software.NAME, software.VERSION, software.BUILD, software.INSTALL_STATUS,

software.INSTALL_DATE, software.PACKAGE_NAME

FROM main INNER JOIN

hardware ON main.MAC = hardware.MAC INNER JOIN

network ON main.MAC = network.MAC INNER JOIN

software ON main.MAC = software.MAC





Re: Windows Forms Data Controls and Databinding Implement a Progress Bar with a DataSet using VB.NET

Ken Tucker

You need to make a second stored procedure which returns a count of rows. You can not convert a datatable to integer.




Re: Windows Forms Data Controls and Databinding Implement a Progress Bar with a DataSet using VB.NET

nbk5533

Answer to getting the progress bar to work. An engineer on my team figured this one out since I was reading the computer names using the ReadLine method against my textfile. Here's a Sub Submit_Click subroutine that allowed the progress bar to work for me.

Dim PvtSqlConnection As New SqlClient.SqlConnection("Data Source=B001279AE624B;Initial Catalog=platform_validation_tool;Integrated Security=True;Connection Timeout=60")

'Dim command As New SqlCommand("uspSelectAnyPkgName", PvtSqlConnection)

PvtSqlConnection.Open()

If (File.Exists(txtMultCmp.Text)) Then

Dim File2 As New StreamReader(txtMultCmp.Text)

Dim Line2 As String

Dim finished As Boolean = False

Dim i As Integer = 0

ProgressBar1.Maximum = 100

ProgressBar1.Step = 1

While Not finished

Line2 = File2.ReadLine

If Line2 Is Nothing Then

finished = True

Exit While

End If

i = i + 1

End While

File2.Close()

ProgressBar1.Maximum = i + 2

ProgressBar1.PerformStep()

ProgressBar1.Refresh()

Dim File As New StreamReader(txtMultCmp.Text)

Dim Line As String

Dim LineValues() As String

Dim Lines As New ArrayList

finished = False

While Not finished

ProgressBar1.PerformStep()

ProgressBar1.Refresh()

Line = File.ReadLine

If Line Is Nothing Then

finished = True

Exit While

Else

LineValues = Split(Line, "")

Lines.Add(LineValues)

Try

SqlDA_SinglePkgName.SelectCommand.Parameters.Item(1).Value = txtPkgName.Text

SqlDA_SinglePkgName.SelectCommand.Parameters.Item(2).Value = Line

SqlDA_SinglePkgName.Fill(WkstnAndSoftwareVerDS1.uspSelectAnyPkgName)

Catch ex As Exception

MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

'Finally

End Try

End If

End While

PvtSqlConnection.Close()

PvtSqlConnection = Nothing

GC.Collect()

ProgressBar1.PerformStep()

ProgressBar1.Refresh()

Call MsgBox("Execution Complete.", MsgBoxStyle.Information, "Complete")

ProgressBar1.Value = 0

Let me know if this helps anyone. Smile

Wally