|
-
Apr 17th, 2011, 05:29 PM
#1
Thread Starter
Addicted Member
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
-
Apr 18th, 2011, 04:04 AM
#2
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 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
-
Apr 19th, 2011, 07:43 AM
#3
Thread Starter
Addicted Member
-
Apr 20th, 2011, 11:51 AM
#4
Thread Starter
Addicted Member
-
Apr 21st, 2011, 03:03 AM
#5
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
-
Apr 21st, 2011, 04:36 AM
#6
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:
Public Class alex Private Sub alex_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'LOAD TEMP DEMO VALUES Dim I As Int16 = 0 Dim J As Int16 = Me.DataGridView1.Columns.Count Dim k As Int16 Dim c As String = "C" With Me.DataGridView1 .Rows.Add(10) ' i am adding some temp values here in to the cells For k = 0 To J - 1 For I = 0 To 10 .Rows(I).Cells(k).Value = c & I Next Next End With End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'now cross check the values of column header '& cell0 values (in your case cell5) with some other value 'if both values are equal then make cell(1) value as "DA" Dim I, J As Int16 Dim ValueFoundinDatabase As String = "C1" 'ASSUME this is the comparison values u found from database Dim ValueFoundinDatagridView_ColumnHeaderText As String = Me.DataGridView1.Columns(0).HeaderText Dim ValueFoundinDatagridView_Cell5 As String With Me.DataGridView1 J = .Rows.Count For I = 0 To J - 1 'now DA making ValueFoundinDatagridView_Cell5 = .Rows(I).Cells(0).Value 'here u need to check the Column header text + cell(5) value 'with database values If ValueFoundinDatagridView_Cell5 = ValueFoundinDatabase AndAlso _ ValueFoundinDatagridView_ColumnHeaderText = ValueFoundinDatabase Then .Rows(I).Cells(1).Value = "DA" End If Next End With End Sub End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|