如何将一列的值从datagridview传输到文本框? [英] How to transfer a value of one column from datagridview to textbox?
问题描述
我需要帮助....我有一个价值女巫导入到datagridview中...在datagridview中...它在列状态下显示4列名为,日期,状态,位置和时间....的列. ,位置,时间和日期有5行...我想获取列时间下的值,并在单击名为"transfer"的按钮后将其传输到TextBox,我应该编码什么正确的代码? />
这是我从数据库中选择值到datagridview的代码,其中显示了列日期,状态,位置和时间
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
我尝试过的事情:
iv尝试过此代码,但我认为它不合适.
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
推荐答案
我得到了此代码的答案
I got the answer ty for this code
= CStr=(dataGridView1(3, 7).Value)
这篇关于如何将一列的值从datagridview传输到文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!