Results 1 to 6 of 6

Thread: DataGridView and SQL Selection

  1. #1

    Thread Starter
    Addicted Member Alexandru_mbm's Avatar
    Join Date
    Jul 2007
    Location
    VBForums.com
    Posts
    157

    DataGridView and SQL Selection

    Dear firends,

    I want to put the value "Da" to all the Cells of the CurrentRow where the "Cell(5).Value=SOMETHING" and the "ColumnHeaderText=SOMETHING" it's found.



    Code:
            For Each rand As DataGridViewRow In Me.dgv_lista_repere.Rows
                For Each coloana As DataGridViewColumn In dgv_lista_repere.Columns
    
                    Try
    
                        conectare_db()
    
                        Dim rezultat As String = "SELECT  lista_indicatori_cursanti.cnp, nomenclator_indicatori.denumire FROM lista_indicatori_cursanti, nomenclator_indicatori WHERE nomenclator_indicatori.denumire=(SELECT nomenclator_indicatori.denumire FROM nomenclator_indicatori WHERE nomenclator_indicatori.id=lista_indicatori_cursanti.id_indicator AND lista_indicatori_cursanti.cnp='" & rand.Cells(5).Value & "');"
                        command_exec = New SqlClient.SqlCommand(rezultat, conexiune)
                        data_reader = command_exec.ExecuteReader
    
    
                        If (data_reader.Read = True) Then
    
                            Dim cnp_cursant As String = data_reader(0)
                            Dim denumire_indicator As String = data_reader(1)
    
                            If rand.Cells(5).Value = cnp_cursant AndAlso coloana.HeaderText = denumire_indicator Then
    
                                rand.Cells(coloana.Index).Value = "Da"
    
                            End If
    
                        Else
                        End If
    
                        deconectare_db()
    
                    Catch ex As Exception
                        deconectare_db()
                        MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    End Try
    
                Next coloana
            Next rand
    Last edited by Alexandru_mbm; Apr 17th, 2011 at 05:34 PM.
    I'm still learning VB.NET
    Sorry for my bad english
    Thanks for your help

  2. #2
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: DataGridView and SQL Selection

    ALEX
    it is difficult for me to understand your code as it is in a language other than english
    i understood your requirement is this way.

    u want to replace the value of the cell
    vb Code:
    1. Cell(5).Value
    if the
    Code:
    Cell(5).Value = 'x'
    and when the row is Current row that means selected

    if right pl reply i can help u
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  3. #3

    Thread Starter
    Addicted Member Alexandru_mbm's Avatar
    Join Date
    Jul 2007
    Location
    VBForums.com
    Posts
    157

    Re: DataGridView and SQL Selection

    Yes it's true English it's not my best Goal...

    The problem is like that.

    The current DataGridView contains data from 3 tables...



    1. I want to read the value of the Cell(5) from the current Row (For Each Loop)

    2. In the same time i want to read the every ColmnHeaderText (For Each Loop).

    3. If the value of Cell(5) and the ColumnHeaderText it's found in the DataBase then to Write in the INTERSECTION Cell the value "Da" (alias Yes in English).




    My problem with the current code:

    If the condition is meet.... only the first cell si marked with "Da" and afert that is going to the next Row... it's not verifying all the Columns.
    I'm still learning VB.NET
    Sorry for my bad english
    Thanks for your help

  4. #4

    Thread Starter
    Addicted Member Alexandru_mbm's Avatar
    Join Date
    Jul 2007
    Location
    VBForums.com
    Posts
    157

    Re: DataGridView and SQL Selection

    no one can help me with this ?
    I'm still learning VB.NET
    Sorry for my bad english
    Thanks for your help

  5. #5
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: DataGridView and SQL Selection

    alex i was busy with my work & out of station for 3 days i will answer please give me some time
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

  6. #6
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: DataGridView and SQL Selection

    Alex cross check this & reply

    here i have used a datagridview + button control & loaded some temp data in to datagrid view cells
    & cross checked each value with some other value & made "DA"
    vb Code:
    1. Public Class alex
    2.  
    3.     Private Sub alex_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.  
    5.         'LOAD TEMP DEMO VALUES
    6.         Dim I As Int16 = 0
    7.         Dim J As Int16 = Me.DataGridView1.Columns.Count
    8.         Dim k As Int16
    9.  
    10.         Dim c As String = "C"
    11.  
    12.         With Me.DataGridView1
    13.             .Rows.Add(10)
    14.             ' i am adding some temp values here in to the cells
    15.             For k = 0 To J - 1
    16.                 For I = 0 To 10
    17.                     .Rows(I).Cells(k).Value = c & I
    18.                 Next
    19.             Next
    20.         End With
    21.  
    22.     End Sub
    23.  
    24.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    25.  
    26.         'now cross check the values of column header
    27.         '& cell0 values (in your case cell5) with some other value
    28.         'if both values are equal then make cell(1) value as "DA"
    29.  
    30.         Dim I, J As Int16
    31.         Dim ValueFoundinDatabase As String = "C1" 'ASSUME this is the comparison values u found from database
    32.         Dim ValueFoundinDatagridView_ColumnHeaderText As String = Me.DataGridView1.Columns(0).HeaderText
    33.         Dim ValueFoundinDatagridView_Cell5 As String
    34.  
    35.         With Me.DataGridView1
    36.             J = .Rows.Count
    37.  
    38.             For I = 0 To J - 1
    39.                 'now DA making
    40.                 ValueFoundinDatagridView_Cell5 = .Rows(I).Cells(0).Value
    41.                 'here u need to check the Column header text + cell(5) value
    42.                 'with database values
    43.                 If ValueFoundinDatagridView_Cell5 = ValueFoundinDatabase AndAlso _
    44.                     ValueFoundinDatagridView_ColumnHeaderText = ValueFoundinDatabase Then
    45.                     .Rows(I).Cells(1).Value = "DA"
    46.                 End If
    47.  
    48.             Next
    49.  
    50.         End With
    51.  
    52.     End Sub
    53. End Class
    The averted nuclear war
    My notes:

    PrOtect your PC. MSDN Functions .OOP LINUX forum
    .LINQ LINQ videous
    If some one helps you please rate them with out fail , forum doesn't expects any thing other than this

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width