vs2010中用datagridview控件显示SQL server数据库中表A 的数据并进行输入和修改,现在我想简化输入操作 5
比如表A中有字段“地类”,地类在另一个表B里有地类分类代码,比如农地为1001,想要在datagridview地类列里输入1001,单元格将显示农地,,,,,,求大神指点...
比如表A中有字段“地类”,地类在另一个表B里有地类分类代码,比如农地为1001,想要在datagridview地类列里输入1001,单元格将显示农地,,,,,,求大神指点思路、不胜感激
展开
1个回答
展开全部
Private Sub DataGridView1_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles view1.CellEndEdit
view1.Rows(e.RowIndex).Cells("swid").Value =(get_yid(view1.Rows(e.RowIndex).Cells("swid").Value))
End Sub
Public Function get_yid(ByVal t_swid As String) As String
Dim g_m As New SqlCommand
g_m.Connection = sql_conn
g_m.CommandText = "select yid as id1 from swb where swid=@swid"
g_m.Parameters.AddWithValue("@swid", t_swid)
sql_conn.Open()
Dim obj1 As Object = g_m.ExecuteScalar()
sql_conn.Close()
If obj1 Is DBNull.Value Then
get_yid = "未知"
Else
get_yid = CType(obj1, String)
End If
Return get_yid
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询