Dataset problem when threading
-
Hi, I'm using VB.NET 2005 Express, and I'm having a go at teaching myself about threading as I want a marquee progress bar displayed on my form whilst it fills a table in a dataset. On my form, I've got a textbox for a database name, and a textbox for simple Select SQL statements. What I'm finding is that when I press 'Go', it populates the DataGridView perfectly, and my progress bar is displayed as I had wanted. However, what I then find is that if I change the contents of the database textbox, or the contents of the SQL textbox, and press 'Go' again, it either doesn't do anything to the DataGridView, or it completely falls over. I'd really appreciate it if you could point me in the right direction to suggest some improvements to the very raw code shown below:
Imports System.Data Imports System.Data.OleDb Public Class Form1 Private ds As New DataSet() Private conn As OleDb.OleDbConnection Private WithEvents backGroundWorker1 As New System.ComponentModel.BackgroundWorker ' THREADING REFERENCES ' http://vbcity.com/forums/faq.asp?fid=15&cat=Threading ' http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1386086&SiteID=1 Private Sub FillDataGridView() Dim strDataSource As String = Me.txtDataSource.Text & "@ol_server;" Dim strConnectionString As String = "Provider=Ifxoledbc.2;" & _ "Password=informix;" & _ "User ID=informix;" & _ "Persist Security Info=True;" & _ "Password=informix;" & _ "Data Source=" & strDataSource.ToString conn = New OleDb.OleDbConnection(strConnectionString) Dim ds As New DataSet() backGroundWorker1.RunWorkerAsync() Dim i As Integer For i = 1 To 100 Me.ProgressBar1.Value = i Next End Sub Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click Me.ProgressBar1.Visible = True Me.ProgressBar1.Refresh() FillDataGridView() End Sub Private Sub backGroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles backGroundWorker1.DoWork Dim da As New OleDb.OleDbDataAdapter Dim cmd As New OleDb.OleDbCommand conn.Open() cmd.Connection = conn
-
Hi, I'm using VB.NET 2005 Express, and I'm having a go at teaching myself about threading as I want a marquee progress bar displayed on my form whilst it fills a table in a dataset. On my form, I've got a textbox for a database name, and a textbox for simple Select SQL statements. What I'm finding is that when I press 'Go', it populates the DataGridView perfectly, and my progress bar is displayed as I had wanted. However, what I then find is that if I change the contents of the database textbox, or the contents of the SQL textbox, and press 'Go' again, it either doesn't do anything to the DataGridView, or it completely falls over. I'd really appreciate it if you could point me in the right direction to suggest some improvements to the very raw code shown below:
Imports System.Data Imports System.Data.OleDb Public Class Form1 Private ds As New DataSet() Private conn As OleDb.OleDbConnection Private WithEvents backGroundWorker1 As New System.ComponentModel.BackgroundWorker ' THREADING REFERENCES ' http://vbcity.com/forums/faq.asp?fid=15&cat=Threading ' http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1386086&SiteID=1 Private Sub FillDataGridView() Dim strDataSource As String = Me.txtDataSource.Text & "@ol_server;" Dim strConnectionString As String = "Provider=Ifxoledbc.2;" & _ "Password=informix;" & _ "User ID=informix;" & _ "Persist Security Info=True;" & _ "Password=informix;" & _ "Data Source=" & strDataSource.ToString conn = New OleDb.OleDbConnection(strConnectionString) Dim ds As New DataSet() backGroundWorker1.RunWorkerAsync() Dim i As Integer For i = 1 To 100 Me.ProgressBar1.Value = i Next End Sub Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click Me.ProgressBar1.Visible = True Me.ProgressBar1.Refresh() FillDataGridView() End Sub Private Sub backGroundWorker1_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles backGroundWorker1.DoWork Dim da As New OleDb.OleDbDataAdapter Dim cmd As New OleDb.OleDbCommand conn.Open() cmd.Connection = conn
What specific error are you getting when the app falls over?
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus