Please Create two tables.
1. mst_employees
USE [MyDatabase]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[mst_employees](
[Emp_ID] [int] NULL,
[Name] [varchar](50) NULL,
[Gender] [char](10) NULL,
[Position] [varchar](50) NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
2. emp_attendance (Sql script is here)
USE [MyDatabase]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[emp_attendance](
[Att_ID] [bigint] IDENTITY(1,1) NOT NULL,
[Emp_ID] [int] NULL,
[Att_Date] [date] NULL,
[Present_Absent] [int] NULL
) ON [PRIMARY]
GO
Imports System.Data
Imports System.Data.SqlClient
Public Class Form7
Public oCn As New System.Data.SqlClient.SqlConnection("Data Source=(local);Initial Catalog=MyDatabase;Uid=sa")
Private Sub Form7_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadData()
End Sub
Sub LoadData()
If oCn.State = ConnectionState.Closed Then
oCn.Open()
End If
Dim cmd As New SqlClient.SqlCommand("Select * from mst_employees", oCn)
Dim da As New SqlClient.SqlDataAdapter(cmd)
Dim ds As New DataSet("bpl")
Dim i As Integer = 0
Me.DataGridView1.Rows.Clear()
Try
da.Fill(ds, "bpl")
If ds.Tables(0).Rows.Count > 0 Then
While (i <> ds.Tables(0).Rows.Count)
Me.DataGridView1.Rows.Add()
Me.DataGridView1.Item(0, i).Value = i + 1
Me.DataGridView1.Item(1, i).Value = ds.Tables(0).Rows(i).Item("Emp_id").ToString
Me.DataGridView1.Item(2, i).Value = ds.Tables(0).Rows(i).Item("Name").ToString
Me.DataGridView1.Item(3, i).Value = ds.Tables(0).Rows(i).Item("Gender").ToString
Me.DataGridView1.Item(4, i).Value = ds.Tables(0).Rows(i).Item("Position").ToString
Me.DataGridView1.Item(5, i).Value = Format(Date.Today, "dd-MMM-yyyy")
i = i + 1
End While
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub btn_submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_submit.Click
Dim oCom As New SqlClient.SqlCommand
Dim oRead As SqlClient.SqlDataReader
If oCn.State = ConnectionState.Closed Then
oCn.Open()
End If
Dim i As Integer = 0
oCom.Connection = oCn
If Me.DataGridView1.Rows.Count > 0 Then
While (i <> Me.DataGridView1.Rows.Count)
oCom.CommandText = "Insert into emp_attendance(Emp_ID,Att_Date,Present_Absent) Values(" & Me.DataGridView1.Item(1, i).Value & ",'" & Me.DataGridView1.Item(5, i).Value & "'," & IIf(Me.DataGridView1.Item(6, i).Value = True, 1, 0) & ")"
oRead = oCom.ExecuteReader()
oRead.Close()
i = i + 1
End While
End If
End Sub
Private Sub btn_checkall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_checkall.Click
Dim i As Integer = 0
If Me.DataGridView1.Rows.Count > 0 Then
While (i <> Me.DataGridView1.Rows.Count)
Me.DataGridView1.Item(6, i).Value = True
i = i + 1
End While
End If
End Sub
End Class