Click here to Skip to main content
16,016,562 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi guys i need help .... i have a value witch import into datagridview...on the datagridview... it display 4 column named , date, status,position,and time .... under column status,position,time and date it have 5 rows... i want to get the values under column time and transfer it to the TextBox once i click the button named "transfer",what is the proper code should i code??

this was my code for selecting value from database into datagridview which is displaying the column date,status,position,and time
Dim arr(100) As String
Try
    conn.Open()
    query = New MySqlCommand("SELECT No,Name,date,status,position,time From
 cash_table WHERE No Like '%" & txtID.Text & "%'", conn)
    dr = query.ExecuteReader()
    While dr.Read
        txtName.Text = dr.GetString("Name")
        txtPosition.Text = dr.GetString("position")

        If dr.HasRows Then
            Do While dr.Read
                arr(0) = dr.Item("date")
                arr(1) = dr.Item("status")
                arr(2) = dr.Item("position")
                arr(2) = dr.Item("time")

                DataGridView1.Rows.Add(arr)
            Loop



            query.ExecuteNonQuery()
        Else
            MsgBox("No Records Found!", MsgBoxStyle.Information, "Search")

        End If
    End While
Catch ex As Exception
    MsgBox(ex.ToString)
Finally
    dr.Close()

    conn.Close()

End Try
Try
    If txtID.Text = "" Then
        DataGridView1.Rows.Clear()
    End If
Catch ex As Exception
    MsgBox("contact your administrator")
End Try


What I have tried:

iv tried this code but i think it is not the appropriate one

conn.Open()
     query = New MySqlCommand("UPDATE attendancetable SET No=@TextBox1.Text,Name=@TextBox2.Text,month=@TextBox3.Text,days=@TextBox4.Text,year=@TextBox5.Text,total=@TextBox6.Text", conn)

     query.Parameters.AddWithValue("No", txtID.Text)
     query.Parameters.AddWithValue("Name", txtName.Text)
     query.Parameters.AddWithValue("month", TextBox2.Text)
     query.Parameters.AddWithValue("days", txtPosition.Text)
     query.Parameters.AddWithValue("year", TextBox3.Text)
     query.Parameters.AddWithValue("total", TextBox4.Text)
     query.ExecuteNonQuery()
     conn.Close()


 End Sub
Posted
Updated 3-Mar-18 15:20pm
v2
Comments
Richard MacCutchan 3-Mar-18 4:43am    
The SQL code is taking values from text boxes and using them as parameters to the query. I do not see any code to copy DataGridView values to text boxes.
CaThey Joy Galias 3-Mar-18 11:55am    
Can u teach me the right one :(
Richard MacCutchan 3-Mar-18 12:04pm    

' Retrieve the cell value for the cell at column 3, row 7.
Dim testValue1 As String = CStr(dataGridView1(3, 7).Value)
CaThey Joy Galias 3-Mar-18 21:19pm    
Ty i got the answer

1 solution

I got the answer ty for this code


= CStr=(dataGridView1(3, 7).Value)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900