0% found this document useful (0 votes)
53 views5 pages

Public Class Data Upload

The document contains code for uploading employee data from an Excel file to a database. It includes: 1. Functions to handle uploading resigned, transferred, and new employee data from a datagrid to database tables. 2. Validation checks on the datagrid columns to ensure the correct headers before uploading. 3. Buttons to select the Excel file, populate the datagrid, and trigger the upload functions. 4. Status messages after each upload displaying the number of successful and failed record insertions.

Uploaded by

bhanodaya p
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views5 pages

Public Class Data Upload

The document contains code for uploading employee data from an Excel file to a database. It includes: 1. Functions to handle uploading resigned, transferred, and new employee data from a datagrid to database tables. 2. Validation checks on the datagrid columns to ensure the correct headers before uploading. 3. Buttons to select the Excel file, populate the datagrid, and trigger the upload functions. 4. Status messages after each upload displaying the number of successful and failed record insertions.

Uploaded by

bhanodaya p
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

Public Class DataUpload

Dim epath As String


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim op As New OpenFileDialog
If op.ShowDialog <> Windows.Forms.DialogResult.OK Then
MsgBox("Select the " & selec & " Excel file to Upload Data")
Else
epath = op.FileName
TextBox1.Text = epath
End If
End Sub
Dim selec As String = ""
Private Sub RadioButton1_CheckedChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
RadioButton1.CheckedChanged
selec = RadioButton1.Text
End Sub

Private Sub RadioButton2_CheckedChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
RadioButton2.CheckedChanged
selec = RadioButton2.Text
End Sub

Private Sub RadioButton3_CheckedChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
RadioButton3.CheckedChanged
selec = RadioButton3.Text
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
Try
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
MyConnection = New System.Data.OleDb.OleDbConnection _
("provider=Microsoft.Jet.OLEDB.4.0; Data Source='" & epath &
"'; Extended Properties=Excel 8.0;")
MyCommand = New System.Data.OleDb.OleDbDataAdapter _
("select * from [" & selec & "$]", MyConnection)
MyCommand.TableMappings.Add("Table", "TestTable")
DtSet = New System.Data.DataSet
MyCommand.Fill(DtSet)

DataGridView1.DataSource = DtSet.Tables(0)
MyConnection.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try

End Sub
Function Resigned_Upload() As Boolean
Dim I As Int32 = 0
Dim SUCC As Int32 = 0
Dim sql As New SQLTransactions.sqltransactions
For I = 0 To DataGridView1.Rows.Count - 2

If DataGridView1.Rows(I).Cells(0).Value.ToString <> "" Then


If sql.nonqry("insert into
tblResigns(Dt,EmpId,UserId,EmpName,Store,Remarks,DoneBy) values('" +
Now.Date + "'," & DataGridView1.Rows(I).Cells(0).Value & "," &
DataGridView1.Rows(I).Cells(0).Value & ", '','',' " +
DataGridView1.Rows(I).Cells(2).Value + "','" +
SQLTransactions.sqltransactions.user + "') ") = True Then

If sql.nonqry("update employee set status=2 where empId=" &


DataGridView1.Rows(I).Cells(0).Value) = True Then
// Employee id based on the Status //

If
SUCC1 = SUCC + 1
Succ1 = success & “ “ & DataGridView1.Rows(I).Cells(0).Value

End If
Else
failed = failed & " " &
DataGridView1.Rows(I).Cells(0).Value
End If

End If
Next

MsgBox("Resigns- Upload Completed " & vbCr & "Successful : " &
SUCC & vbCr & "Failed : " & failed)

End Function
Function Transfer_Upload() As Boolean
Dim I As Int32 = 0
Dim SUCC As Int32 = 0
Dim sql As New SQLTransactions.sqltransactions
For I = 0 To DataGridView1.Rows.Count - 2
If DataGridView1.Rows(I).Cells(0).Value.ToString <> "" Then
If sql.nonqry("insert into
tbltransfer(Dt,EmpId,UserId,EmpName,StoreFrom,StoreTo,Remarks,DoneBy)
values('" + Now.Date + "'," & DataGridView1.Rows(I).Cells(0).Value & ","
& DataGridView1.Rows(I).Cells(0).Value & ", '','',' " +
DataGridView1.Rows(I).Cells(2).Value + "',' " +
DataGridView1.Rows(I).Cells(3).Value + "','" +
SQLTransactions.sqltransactions.user + "') ") = True Then
If sql.nonqry("Update Employee set Location='" +
DataGridView1.Rows(I).Cells(2).Value + "' where empid=" &
DataGridView1.Rows(I).Cells(0).Value) = True Then

SUCC1 = SUCC + 1
End If
Else
failed = failed & " " &
DataGridView1.Rows(I).Cells(0).Value
End If
End If
Next

MsgBox("Transfers- Upload Completed " & vbCr & "Successful : " &
SUCC & vbCr & "Failed : " & failed)
End Function
'employee data upload...............

Function Master_Upload() As Boolean


Dim I As Int32 = 0
Dim SUCC As Int32 = 0
Dim sql As New SQLTransactions.sqltransactions
For I = 0 To DataGridView1.Rows.Count - 2
If DataGridView1.Rows(I).Cells(0).Value.ToString <> "" Then
If sql.nonqry("insert into
Employee(UserId,EmpId,EmpName,Dept,desig,Doj,Location,region) values ("
& DataGridView1.Rows(I).Cells(0).Value & "," &
DataGridView1.Rows(I).Cells(0).Value & ",'" &
(DataGridView1.Rows(I).Cells(1).Value) & "','" &
DataGridView1.Rows(I).Cells(2).Value & "','" &
DataGridView1.Rows(I).Cells(3).Value & "','" + Now.Date + "','" &
DataGridView1.Rows(I).Cells(5).Value & "','" +
SQLTransactions.sqltransactions.region + "') ") = True Then

SUCC = SUCC + 1

Else
failed = failed & " " &
DataGridView1.Rows(I).Cells(0).Value
End If
End If
Next

MsgBox("Transfers- Upload Completed " & vbCr & "Successful : " &
SUCC & vbCr & "Failed : " & failed)
End Function

Function valida(ByVal fn As String) As Boolean


Dim tmp As Boolean = False
If fn = "Resigned" Then
If DataGridView1.Columns.Count <> 3 Then
Return False
End If
tmp = check(DataGridView1.Columns(0).HeaderText, "REMPID")
If tmp = False Then
Return False
End If
tmp = check(DataGridView1.Columns(1).HeaderText, "RDATE")
If tmp = False Then
Return False
End If
tmp = check(DataGridView1.Columns(2).HeaderText, "RREMARKS")
If tmp = False Then
Return False
End If
resigned_upload()
ElseIf fn = "Transfered" Then
If DataGridView1.Columns.Count <> 4 Then
Return False
End If
tmp = check(DataGridView1.Columns(0).HeaderText, "TEMPID")
If tmp = False Then
Return False
End If
tmp = check(DataGridView1.Columns(1).HeaderText, "TDATE")
If tmp = False Then
Return False
End If

tmp = check(DataGridView1.Columns(2).HeaderText,
"TLOCATION")
If tmp = False Then
Return False
End If

tmp = check(DataGridView1.Columns(3).HeaderText, "TREMARKS")


If tmp = False Then
Return False
End If
Transfer_Upload()
Else

If DataGridView1.Columns.Count <> 6 Then


Return False
End If
Master_Upload()

End If
Return True
End Function
Function check(ByVal v1 As String, ByVal v2 As String) As Boolean
If v1 = v2 Then
check = True
Else
check = False
End If
End Function
Function upload_employee()
upload_employee = ""
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
selec = RadioButton1.Text
End Sub
Dim failed As String = ""
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
failed = ""
If valida(selec) Then

End If
End Sub
End Class

If Succ1= success then


Status = Success else
Staus = Failed

In validations….(This shuld be repeated in all the actions)

You have to write tmp = check(DataGridView1.Columns(7).HeaderText,


"TSTATUS")
If tmp = False Then
Return False
End If

You might also like