我有1個DataGridView有3列,1個按鈕名爲AssignID,1有數據庫EmployeeList表。的DataGridView在Datagridview中自動分配員工號碼
的列
- 列1 =僱員
- 列2 = EmployeeName
- 列3 =部門
我粘貼EmployeeName和部的數據將excel中的轉換爲DataGridView,並將第1列留作空白。我的問題是,當我按下按鈕AssignID時,如何在DataGridView中自動分配每個員工的EmployeeID。最後的IDNumber在數據庫中是10000.
感謝您的幫助。我還在學習vb.net。提前致謝。
進出口使用下面的代碼:
Private Sub AssignID_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AssignID.Click
Dim Dbcon As New OleDbConnection(connStr)
Dbcon.Open()
Dim query As String
Dim dbup As New OleDbCommand
Try
query = "SELECT Max (EmployeeID) from EmployeeList"
dbup = New OleDbCommand(query, Dbcon)
Dim EmpID As Integer
EmpID = dbup.ExecuteScalar
Dim i2 As Integer
i2 = Me.NewEmployeesDataGridview.CurrentRow.Index
NewEmployeesDataGridview.Item(0, i2).Value() = EmpID
For x As Integer = 0 To NewEmployeesDataGridview.Rows.Count - 2
NewEmployeesDataGridview.Rows(x).Cells(0).Value = NewEmployeesDataGridview.Rows(0).Cells(0).Value + 1
Next
NewEmployeesDataGridview.AllowUserToAddRows = False
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
我對你的問題有點困惑。你是否想要如何在datagridview單元格中找到合適的人? – Kat 2014-10-28 19:48:41