Question listview datas to database using background worker

evolet10000

Active member
Joined
Nov 22, 2012
Messages
40
Programming Experience
Beginner
[SUB]im trying to make a query that insert all listview datas into database with background worker

here the problem

VB.NET:
[/SUB]
            For Each SAIitem As ListViewItem In ListViewRIS_ITEMS.Items
                 cmd = New SqlClient.SqlCommand("INSERT INTO SAI_ITEMS(SAI_NO, STOCK_NO,  STOCK_CATEGORY, STOCK_DESCRIPTION, STOCK_UNIT, QUANTITY,  STOCK_BALANCE_QTY) VALUES('" & SAI_NO_RESULT & "', '" &  SAIitem.SubItems(0).Text & _
                                                "', '" & SAIitem.SubItems(1).Text & "', '" &  SAIitem.SubItems(2).Text & "', '" & SAIitem.SubItems(3).Text  & "', '" & SAIitem.SubItems(4).Text & "', '" &  SAIitem.SubItems(5).Text & "')", con)
                cmd.Connection = con

                cmd.ExecuteNonQuery()

            Next[SUB]

i get a cross thread error @ listviewRIS_ITEMS.Items, i know that it can be bypass using delegates? but is there another way? i mean like? can i store "listviewRIS_ITEMS" in a variable?
so that my full code will execute smoothly? just need some advice experts :D

heres the full code.

VB.NET:
[/SUB]
    Private Sub ButtonSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSave.Click
        BW_ADDRIS_SAI.RunWorkerAsync()
        frmLoading.ShowDialog()
    End Sub

    Private Sub BW_ADDRIS_SAI_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BW_ADDRIS_SAI.DoWork
        Try
            If con.State = ConnectionState.Open Then
                con.Close()
            End If
            con.Open()
            'SAI QUERY
            Dim SAI As String = "SAI"
            Dim SAIYEARNOW = Year(Now)
            Dim SAIMONTHNOW = Month(Now)
            Dim SAICOUNT As Integer = SAIgetcount()
            Dim SAIDATENOW As Date = Now()
            Dim SAI_NO_RESULT As String
            SAI_NO_RESULT = GENERATE_SAI_NO(SAI, SAIYEARNOW, SAIMONTHNOW, SAICOUNT)
            'RIS QUERY
            Dim RIS As String = "RIS"
            Dim RISYEARNOW = Year(Now)
            Dim RISMONTHNOW = Month(Now)
            Dim RISCOUNT As Integer = RISgetcount()
            Dim RISDATENOW As Date = Now()
            Dim RIS_NO_RESULT As String
            RIS_NO_RESULT = GENERATE_RIS_NO(RIS, RISYEARNOW, RISMONTHNOW, RISCOUNT)
            '==============(START)INSERT INTO SAI=============='
            cmd = New SqlClient.SqlCommand("INSERT INTO SAI(SAI_NO, OFFICE, DIVISION, PURPOSE, INQUIRED_BY_EMP_NO, INQUIRED_DATE) VALUES('" & SAI_NO_RESULT & "', '" & OFFICE _
                                           & "', '" & DIVISION & "', '" & TextBoxUSER_ADDRIS_PURPOSE.Text & "', '" & EMP_NO & "', '" & SAIDATENOW & "')", con)
            cmd.Connection = con

            cmd.ExecuteNonQuery()
            '==============(END)INSERT INTO SAI=============='
            '==============(START)INSERT INTO SAI ITEMS=============='
            For Each SAIitem As ListViewItem In ListViewRIS_ITEMS.Items
                cmd = New SqlClient.SqlCommand("INSERT INTO SAI_ITEMS(SAI_NO, STOCK_NO, STOCK_CATEGORY, STOCK_DESCRIPTION, STOCK_UNIT, QUANTITY, STOCK_BALANCE_QTY) VALUES('" & SAI_NO_RESULT & "', '" & SAIitem.SubItems(0).Text & _
                                               "', '" & SAIitem.SubItems(1).Text & "', '" & SAIitem.SubItems(2).Text & "', '" & SAIitem.SubItems(3).Text & "', '" & SAIitem.SubItems(4).Text & "', '" & SAIitem.SubItems(5).Text & "')", con)
                cmd.Connection = con

                cmd.ExecuteNonQuery()

            Next

            '==============(END)INSERT INTO SAI ITEMS=============='
            '==============(START)INSERT INTO RIS=============='
            cmd = New SqlClient.SqlCommand("INSERT INTO RIS(RIS_NO, RIS_DATE, OFFICE, DIVISION, SAI_NO, SAI_DATE, PURPOSE, REQUISITIONER_EMP_NO, REQUESTED_DATE, OFFICE_HEAD_EMP_NO) VALUES('" & RIS_NO_RESULT & "', '" & RISDATENOW & _
                                           "', '" & OFFICE & "', '" & DIVISION & "', '" & SAI_NO_RESULT & "', '" & SAIDATENOW & "', '" & TextBoxUSER_ADDRIS_PURPOSE.Text & "', '" & EMP_NO & "', '" & RISDATENOW & "', '" & TextBoxADD_RIS_APR_EMP.Text & "')", con)
            cmd.Connection = con

            cmd.ExecuteNonQuery()
            '==============(END)INSERT INTO RIS=============='
            '==============(START)INSERT INTO RIS ITEMS=============='
            For Each RISitem As ListViewItem In ListViewRIS_ITEMS.Items
                cmd = New SqlClient.SqlCommand("INSERT INTO RIS_ITEMS(RIS_NO, SAI_NO, STOCK_NO, STOCK_CATEGORY, STOCK_DESCRIPTION, STOCK_UNIT, QUANTITY) VALUES('" & RIS_NO_RESULT & "', '" & SAI_NO_RESULT & "', '" & RISitem.SubItems(0).Text & _
                                               "', '" & RISitem.SubItems(1).Text & "', '" & RISitem.SubItems(2).Text & "', '" & RISitem.SubItems(3).Text & "', '" & RISitem.SubItems(4).Text & "')", con)
                cmd.Connection = con

                cmd.ExecuteNonQuery()
            Next
            '==============(END)INSERT INTO RIS ITEMS=============='
            '==================TEMPORARY BALANCE===================='
            'For Each RISitemB_QTY As ListViewItem In ListViewRIS_ITEMS.Items
            'Dim temp_bal As Integer = TextBoxBALANCE_QTY.Text
            'Dim req_qty As Integer = RISitemB_QTY.SubItems(4).Text
            'Dim new_temp_bal As Integer = temp_bal - req_qty
            'cmd = New SqlClient.SqlCommand("UPDATE STOCK SET STOCK_TEMP_BALANCE_QTY = '" & new_temp_bal & "' WHERE STOCK_NO = '" & RISitemB_QTY.SubItems(0).Text & "'", con)
            'cmd.Connection = con

            'cmd.ExecuteNonQuery()
            'Next
            '==================END TEMPORARY BALANCE===================='
            con.Close()
            myFlag = True
            RISNORESULT = RIS_NO_RESULT
            SAINORESULT = SAI_NO_RESULT
        Catch ex As Exception
            myBWFlag = True
            myErr = ex.Message
        End Try
    End Sub

    Private Sub BW_ADDRIS_SAI_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BW_ADDRIS_SAI.RunWorkerCompleted
        frmLoading.Close()
        If myFlag = True Then
            frmDialog.LabelDialogDotText.Text = "MESSAGE: ADD RIS AND SAI"
            frmDialog.LabelDialogDotText.ForeColor = Color.Red
            frmDialog.TextBox1.Text = "Successful"
            frmDialog.ShowDialog()
            frmUSER_FRAME.SHOW_USER_SAI()
            MsgBox("RIS AND SAI HAS BEEN ADDED")
            TabControlMainContent.SelectedIndex = 1
        ElseIf myBWFlag = True Then
            frmDialog.LabelDialogDotText.Text = "WARNING: Network Error"
            frmDialog.LabelDialogDotText.ForeColor = Color.Red
            frmDialog.TextBox1.Text = myErr
            frmDialog.ShowDialog()
        End If
    End Sub    Public Function GENERATE_SAI_NO(ByVal SAI As String, ByVal SAIYEARNOW As String, ByVal SAIMONTHNOW As String, ByVal SAICOUNT As Integer) As String

        Dim SAI_NO As String

        SAI_NO = SAI & "-" & SAIYEARNOW & "-" & "0" & SAIMONTHNOW & "-" & "0" & SAICOUNT

        Return SAI_NO
    End Function

    Public Function SAIgetcount() As Integer
        If con.State = ConnectionState.Open Then
            con.Close()
        End If
        con.Open()

        cmd = New SqlClient.SqlCommand("SELECT COUNT(*) FROM SAI", con)

        Return cmd.ExecuteScalar
        con.Close()
    End Function

    Public Function GENERATE_RIS_NO(ByVal RIS As String, ByVal RISYEARNOW As String, ByVal RISMONTHNOW As String, ByVal RISCOUNT As Integer) As String

        Dim RIS_NO As String

        RIS_NO = RIS & "-" & RISYEARNOW & "-" & "0" & RISMONTHNOW & "-" & "0" & RISCOUNT

        Return RIS_NO
    End Function

    Public Function RISgetcount() As Integer
        If con.State = ConnectionState.Open Then
            con.Close()
        End If
        con.Open()

        cmd = New SqlClient.SqlCommand("SELECT COUNT(*) FROM RIS", con)

        Return cmd.ExecuteScalar
        con.Close()
    End Function[SUB]
[/SUB]
 
Hi,

The reason why you are getting this error is due to the fact that you are trying to access the ListView, which was created on the UI thread, from a secondary thread and accessing objects created on separate threads is simply not allowed.

If you want to use your ListView in your BackgroundWorker then you need to pass your ListView as an argument to the BackgroundWorker. Have a look at this example:-

VB.NET:
Public Class Form1
 
  Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
    'Cast the e.Argument object to the Correct type that was passed to it
    Dim myListView As ListView = DirectCast(e.Argument, ListView)
    'Perform your code here using the the myListView object...
  End Sub
 
  Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    'Pass the listview you need to work with as an argument to the BackgroundWorker
    BackgroundWorker1.RunWorkerAsync(ListView1)
  End Sub
End Class

Hope that helps.

Cheers,

Ian
 
thanks for the quick responce, im still a beginner @vb.net, i tried to modify my codes,
it now look like this

VB.NET:
#Region "ADD SAI AND RIS"

    Private Sub ButtonSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSave.Click
        BW_ADDRIS_SAI.RunWorkerAsync(ListViewRIS_ITEMS)
        frmLoading.ShowDialog()
    End Sub

    Private Sub BW_ADDRIS_SAI_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BW_ADDRIS_SAI.DoWork
        Try
            If con.State = ConnectionState.Open Then
                con.Close()
            End If
            con.Open()
            'SAI QUERY
            Dim SAI As String = "SAI"
            Dim SAIYEARNOW = Year(Now)
            Dim SAIMONTHNOW = Month(Now)
            Dim SAICOUNT As Integer = SAIgetcount()
            Dim SAIDATENOW As Date = Now()
            Dim SAI_NO_RESULT As String
            SAI_NO_RESULT = GENERATE_SAI_NO(SAI, SAIYEARNOW, SAIMONTHNOW, SAICOUNT)
            'RIS QUERY
            Dim RIS As String = "RIS"
            Dim RISYEARNOW = Year(Now)
            Dim RISMONTHNOW = Month(Now)
            Dim RISCOUNT As Integer = RISgetcount()
            Dim RISDATENOW As Date = Now()
            Dim RIS_NO_RESULT As String
            RIS_NO_RESULT = GENERATE_RIS_NO(RIS, RISYEARNOW, RISMONTHNOW, RISCOUNT)

            Dim myListView As ListView = DirectCast(e.Argument, ListView)'here's what we added

            '==============(START)INSERT INTO SAI=============='
            cmd = New SqlClient.SqlCommand("INSERT INTO SAI(SAI_NO, OFFICE, DIVISION, PURPOSE, INQUIRED_BY_EMP_NO, INQUIRED_DATE) VALUES('" & SAI_NO_RESULT & "', '" & OFFICE _
                                           & "', '" & DIVISION & "', '" & TextBoxUSER_ADDRIS_PURPOSE.Text & "', '" & EMP_NO & "', '" & SAIDATENOW & "')", con)
            cmd.Connection = con

            cmd.ExecuteNonQuery()
            '==============(END)INSERT INTO SAI=============='
            '==============(START)INSERT INTO SAI ITEMS=============='
            For Each SAIitem As ListViewItem In myListView.Items'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<here
                cmd = New SqlClient.SqlCommand("INSERT INTO SAI_ITEMS(SAI_NO, STOCK_NO, STOCK_CATEGORY, STOCK_DESCRIPTION, STOCK_UNIT, QUANTITY, STOCK_BALANCE_QTY) VALUES('" & SAI_NO_RESULT & "', '" & SAIitem.SubItems(0).Text & _
                                               "', '" & SAIitem.SubItems(1).Text & "', '" & SAIitem.SubItems(2).Text & "', '" & SAIitem.SubItems(3).Text & "', '" & SAIitem.SubItems(4).Text & "', '" & SAIitem.SubItems(5).Text & "')", con)
                cmd.Connection = con

                cmd.ExecuteNonQuery()

            Next

            '==============(END)INSERT INTO SAI ITEMS=============='
            '==============(START)INSERT INTO RIS=============='
            cmd = New SqlClient.SqlCommand("INSERT INTO RIS(RIS_NO, RIS_DATE, OFFICE, DIVISION, SAI_NO, SAI_DATE, PURPOSE, REQUISITIONER_EMP_NO, REQUESTED_DATE, OFFICE_HEAD_EMP_NO) VALUES('" & RIS_NO_RESULT & "', '" & RISDATENOW & _
                                           "', '" & OFFICE & "', '" & DIVISION & "', '" & SAI_NO_RESULT & "', '" & SAIDATENOW & "', '" & TextBoxUSER_ADDRIS_PURPOSE.Text & "', '" & EMP_NO & "', '" & RISDATENOW & "', '" & TextBoxADD_RIS_APR_EMP.Text & "')", con)
            cmd.Connection = con

            cmd.ExecuteNonQuery()
            '==============(END)INSERT INTO RIS=============='
            '==============(START)INSERT INTO RIS ITEMS=============='
            For Each RISitem As ListViewItem In myListView.Items'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<here
                cmd = New SqlClient.SqlCommand("INSERT INTO RIS_ITEMS(RIS_NO, SAI_NO, STOCK_NO, STOCK_CATEGORY, STOCK_DESCRIPTION, STOCK_UNIT, QUANTITY) VALUES('" & RIS_NO_RESULT & "', '" & SAI_NO_RESULT & "', '" & RISitem.SubItems(0).Text & _
                                               "', '" & RISitem.SubItems(1).Text & "', '" & RISitem.SubItems(2).Text & "', '" & RISitem.SubItems(3).Text & "', '" & RISitem.SubItems(4).Text & "')", con)
                cmd.Connection = con

                cmd.ExecuteNonQuery()
            Next
            '==============(END)INSERT INTO RIS ITEMS=============='
            con.Close()
            myFlag = True
            RISNORESULT = RIS_NO_RESULT
            SAINORESULT = SAI_NO_RESULT
        Catch ex As Exception
            myBWFlag = True
            myErr = ex.Message
        End Try
    End Sub

    Private Sub BW_ADDRIS_SAI_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BW_ADDRIS_SAI.RunWorkerCompleted
        frmLoading.Close()
        If myFlag = True Then
            frmDialog.LabelDialogDotText.Text = "MESSAGE: ADD RIS AND SAI"
            frmDialog.LabelDialogDotText.ForeColor = Color.Red
            frmDialog.TextBox1.Text = "Successful"
            frmDialog.ShowDialog()
            frmUSER_FRAME.SHOW_USER_SAI()
            MsgBox("RIS AND SAI HAS BEEN ADDED")
            TabControlMainContent.SelectedIndex = 1
        ElseIf myBWFlag = True Then
            frmDialog.LabelDialogDotText.Text = "WARNING: Network Error"
            frmDialog.LabelDialogDotText.ForeColor = Color.Red
            frmDialog.TextBox1.Text = myErr
            frmDialog.ShowDialog()
        End If
    End Sub
#End Region

#Region "FUNCTIONS"
    Public Function GENERATE_SAI_NO(ByVal SAI As String, ByVal SAIYEARNOW As String, ByVal SAIMONTHNOW As String, ByVal SAICOUNT As Integer) As String

        Dim SAI_NO As String

        SAI_NO = SAI & "-" & SAIYEARNOW & "-" & "0" & SAIMONTHNOW & "-" & "0" & SAICOUNT

        Return SAI_NO
    End Function

    Public Function SAIgetcount() As Integer
        If con.State = ConnectionState.Open Then
            con.Close()
        End If
        con.Open()

        cmd = New SqlClient.SqlCommand("SELECT COUNT(*) FROM SAI", con)

        Return cmd.ExecuteScalar
        con.Close()
    End Function

    Public Function GENERATE_RIS_NO(ByVal RIS As String, ByVal RISYEARNOW As String, ByVal RISMONTHNOW As String, ByVal RISCOUNT As Integer) As String

        Dim RIS_NO As String

        RIS_NO = RIS & "-" & RISYEARNOW & "-" & "0" & RISMONTHNOW & "-" & "0" & RISCOUNT

        Return RIS_NO
    End Function

    Public Function RISgetcount() As Integer
        If con.State = ConnectionState.Open Then
            con.Close()
        End If
        con.Open()

        cmd = New SqlClient.SqlCommand("SELECT COUNT(*) FROM RIS", con)

        Return cmd.ExecuteScalar
        con.Close()
    End Function
#End Region

but the erros still occurs.....

VB.NET:
Cross-thread operation not valid: Control 'ListViewRIS_ITEMS' accessed from a thread other than the thread it was created on.

i tried to put BW_ADDRIS_SAI.RunWorkerAsync(ListViewRIS_ITEMS)
both to Private Sub ButtonSave_Click and Form_Load it didn't give me an error but it seems

it ignore my code right here, when i check my database tables

VB.NET:
            '==============(START)INSERT INTO SAI ITEMS=============='
             For Each SAIitem As ListViewItem In  myListView.Items'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<here
                 cmd = New SqlClient.SqlCommand("INSERT INTO SAI_ITEMS(SAI_NO, STOCK_NO,  STOCK_CATEGORY, STOCK_DESCRIPTION, STOCK_UNIT, QUANTITY,  STOCK_BALANCE_QTY) VALUES('" & SAI_NO_RESULT & "', '" &  SAIitem.SubItems(0).Text & _
                                                "', '" & SAIitem.SubItems(1).Text & "', '" &  SAIitem.SubItems(2).Text & "', '" & SAIitem.SubItems(3).Text  & "', '" & SAIitem.SubItems(4).Text & "', '" &  SAIitem.SubItems(5).Text & "')", con)
                cmd.Connection = con

                cmd.ExecuteNonQuery()

            Next

            '==============(END)INSERT INTO SAI ITEMS=============='

'''''''''''''''''''''''''''''''And here'''''''''''''''''''''''''

            '==============(START)INSERT INTO RIS ITEMS=============='
            For Each RISitem As ListViewItem In myListView.Items'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<here
                 cmd = New SqlClient.SqlCommand("INSERT INTO RIS_ITEMS(RIS_NO, SAI_NO,  STOCK_NO, STOCK_CATEGORY, STOCK_DESCRIPTION, STOCK_UNIT, QUANTITY)  VALUES('" & RIS_NO_RESULT & "', '" & SAI_NO_RESULT & "',  '" & RISitem.SubItems(0).Text & _
                                                "', '" & RISitem.SubItems(1).Text & "', '" &  RISitem.SubItems(2).Text & "', '" & RISitem.SubItems(3).Text  & "', '" & RISitem.SubItems(4).Text & "')", con)
                cmd.Connection = con

                cmd.ExecuteNonQuery()
            Next

but again thanks for spreading some lights :D,
 
Hi,

The principal I quoted in my first post is accurate however I have never actually had to pass a ListView to a BackgroundWorker myself and I never tested this first. As it is, the BackgroundWorker is still trying to Reference the ListViewItems when you perform your For loop which is why you are still getting the error. My apologies for not seeing that but at least we have learnt something new.

So, to get round this you need to create a list of ListViewItems and then pass this list to the BackgroundWorker. Have a look at this example:-

VB.NET:
Public Class Form1
 
  Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Dim myLVICollection As New List(Of ListViewItem)
 
    For Each LVI As ListViewItem In ListViewRIS_ITEMS.Items
      myLVICollection.Add(DirectCast(LVI.Clone, ListViewItem))
    Next
    BackgroundWorker1.RunWorkerAsync(myLVICollection)
  End Sub
 
  Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
    Dim myListViewItems As List(Of ListViewItem) = DirectCast(e.Argument, List(Of ListViewItem))
 
    For Each LVI As ListViewItem In myListViewItems
      MsgBox(LVI.Text)
    Next
  End Sub
 
  Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    For Counter As Integer = 1 To 10
      Dim LVI As New ListViewItem
      LVI.Text = "Test"
      LVI.SubItems.Add("Test")
      ListViewRIS_ITEMS.Items.Add(LVI)
    Next
  End Sub
End Class

Notice the slight modification to the For Loop to accommodate the iteration of a List(Of ListViewItems) instead of a ListView.

Also, after having another look at your code, you seem to be trying to access other TextBox's on the UI thread from the BackgroundWorker. If so, that you are going to have to consider these same principals to get the information from the controls.

Hope that helps.

Cheers,

Ian
 
Hi,

The reason why you are getting this error is due to the fact that you are trying to access the ListView, which was created on the UI thread, from a secondary thread and accessing objects created on separate threads is simply not allowed.

If you want to use your ListView in your BackgroundWorker then you need to pass your ListView as an argument to the BackgroundWorker. Have a look at this example:-

VB.NET:
Public Class Form1
 
  Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
    'Cast the e.Argument object to the Correct type that was passed to it
    Dim myListView As ListView = DirectCast(e.Argument, ListView)
    'Perform your code here using the the myListView object...
  End Sub
 
  Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    'Pass the listview you need to work with as an argument to the BackgroundWorker
    BackgroundWorker1.RunWorkerAsync(ListView1)
  End Sub
End Class

Hope that helps.

Cheers,

Ian

That's no use Ian. The ListView is still a control created on the UI thread. How you access reference to it doesn't change that. The simple fact is that you CAN NOT access the ListView at all from a secondary thread. If you were going to stick with the ListView then you need to get all the data out of the ListView on the UI thread first, then do the data access on the secondary thread.

Of course, the correct answer is simple: don't use a ListView. The ListView is NOT a grid control and should not be used as one. If you want a grid then use a grid, i.e. a DataGridView. If you're working with data then you should use a data adapter to populate a DataTable and then bind that to a DataGridView. Any changes made to the data affect both the grid and the table regardless of which end they are made at. As such, when it comes time to save the data, the grid is completely irrelevant. You simply use the same data adapter to save the entire contents of the DataTable back to the database. No mess, no fuss.
 
Hi jcmilhinney,

Thanks for that and Yes I had missed that point altogether. I posted a fix in post No.4 but I do agree that your fix is the overall better way to do this.

Thanks and kind regards,

Hope all that helps evolet10000.

Ian
 
hi sir ian

you're forum description really describes you., IDOL :D., its working now :D dozen of thanks for you., you save the day and my days to come i guess? :D
even though im still a bit confused, maybe i should take a look at it again and again to grasp it :D.,godbless you sir :D

hi sir jcmilhinney

thanks for the advice sir :D, its just so happen that i prefered listview than datagridview

and yeah using data adapters is great but i prefer the manual way(source codes) than tableadapters :D

thanks again., advice compiled :D
 
thanks for the advice sir :D, its just so happen that i prefered listview than datagridview
It shouldn't just happen. There should be a reason for it either way. Quite simply, if you're not using the multiple views or grouping functionality that the ListView provides then there is absolutely no justification for using. Doing so is bad.
and yeah using data adapters is great but i prefer the manual way(source codes) than tableadapters :D
A data adapter is not a table adapter. Using a data adapter IS doing it in code. Even if you do use a ListView, which you absolutely shouldn't, you should still use a DataTable and a data adapter. The code you have could be improved considerably so, if you're trying to learn how to use ADO.NET properly, you have a way to go I'm afraid. To that end, you might check out these two ADO.NET related posts of mine:

Retrieving and Saving Data in Databases
Using Parameters in ADO.NET
 
Thanks for the advice sir., ill take a note of that...

yeah im still a fetus when it comes to vb.net and ado.net., thanks for the links sir.,ill take some time to learn those :D

thanks again + karma :D
 

Latest posts

Back
Top