我有一个像这样的datagridview: datagridviewMut
我想直接在datagridview中输入数据。当我输入nip 123456789123456789时,我想从数据库中自动输出数据...并且我使用一个类从数据库中获取数据..但是它没有输出名称..
这是我使用visual basic的编码:
Private Sub DgvUMutasi_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DgvUMutasi.CellEnter
Dim columnName As String = DgvUMutasi.Columns(DgvUMutasi.CurrentCell.ColumnIndex).Name
Dim row As DataGridViewRow = DgvUMutasi.CurrentRow
cp.P_NIP = row.Cells(0).Value.ToString
If columnName = "NIP" And cp.KeypressID() = True Then
row.Cells(1).Value = cp.P_Nama
End If
End Sub
这是keypressID的功能:(编辑:更改代码布局)
Public Function KeypressID() As Boolean
Dim cnn As New SqlConnection(StrConn)
Dim cmmd As New SqlCommand
Dim dreader As SqlDataReader
Dim SQL As String
SQL = "SP_SELECT_PEGAWAI"
cnn.Open()
cmmd = New SqlCommand(SQL, cnn)
cmmd.CommandType = CommandType.StoredProcedure
cmmd.Parameters.Clear()
cmmd.CommandText = SQL
cmmd.Parameters.Add(New SqlParameter("@P1", NIP))
dreader = cmmd.ExecuteReader
If dreader.Read = True Then
Dim ImgByte() As Byte = dreader("Foto")
Dim ImgStr As New System.IO.MemoryStream(ImgByte)
Me.Foto = Image.FromStream(ImgStr)
Me.Nama = dreader("Nama")
Me.Jabatan = dreader("Jabatan")
Me.Daerah = dreader("Daerah")
Me.Tsk = dreader("Tsk_Jab")
Me.PktPns = dreader("Pnk_Pns")
Me.GolPns = dreader("Gol_Pns")
Me.TmtPns = dreader("Tmt_Pns")
Me.Pensiun = dreader("Pensiun")
Return True
Else
Me.Foto = Nothing
Me.Nama = ""
Me.Jabatan = ""
Me.Daerah = ""
Me.Tsk = Date.Now
Me.PktPns = ""
Me.GolPns = ""
Me.TmtPns = Date.Now
Me.Pensiun = Date.Now
Return False
End If
cnn.Close()
End Function
哪一部分错了?