Try this Code below.
Method To Get List based on Date:
Private Sub ListAttDetails()
If obj.mycon.State = ConnectionState.Open Then
obj.mycon.Close()
End If
Dim adp As New OleDbDataAdapter
Dim ds As New DataSet
Try
obj.mycon.ConnectionString = obj.conString
obj.mycon.Open()
cmd = obj.mycon.CreateCommand
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "PrcAttRpt"
Call PassParam(cmd, "LIST_ATT_DET")
cmd.ExecuteNonQuery()
adp.SelectCommand = cmd
adp.Fill(ds)
Me.dgv_empdetails.DataSource = ds.Tables(0).DefaultView
obj.mycon.Close()
cmd.Parameters.Clear()
Catch ex As Exception
obj.mycon.Close()
MsgBox(ex.Message)
Finally
obj.mycon.Close()
End Try
End Sub
Passing Parameters:
Private Sub PassParam(ByVal CmdObj As OleDbCommand, ByVal QryStr As String)
CmdObj.Parameters.AddWithValue("@QryId", QryStr)
CmdObj.Parameters.AddWithValue("@StrXml", DBNull.Value)
CmdObj.Parameters.AddWithValue("@PkId", DBNull.Value)
If fromDate <> "" Then
CmdObj.Parameters.AddWithValue("@FDate", fromDate)
Else
CmdObj.Parameters.AddWithValue("@FDate", DBNull.Value)
End If
If toDate <> "" Then
CmdObj.Parameters.AddWithValue("@TDate", toDate)
Else
CmdObj.Parameters.AddWithValue("@TDate", DBNull.Value)
End If
If curDate <> "" Then
CmdObj.Parameters.AddWithValue("@Param1", curDate)
Else
CmdObj.Parameters.AddWithValue("@Param1", DBNull.Value)
End If
CmdObj.Parameters.AddWithValue("@Param2", DBNull.Value)
CmdObj.Parameters.AddWithValue("@Param3", DBNull.Value)
CmdObj.Parameters.AddWithValue("@Param4", DBNull.Value)
CmdObj.Parameters.AddWithValue("@Param5", DBNull.Value)
CmdObj.Parameters.AddWithValue("@Param6", DBNull.Value)
CmdObj.Parameters.AddWithValue("@Param7", DBNull.Value)
CmdObj.Parameters.AddWithValue("@Param8", DBNull.Value)
CmdObj.Parameters.AddWithValue("@hdnUsr", UsrNm)
End Sub
In Procedure
SELECT RTRIM(Emp_Name) AS 'Name', RTRIM(Attendance) AS 'Attendance', dbo.gefgDMY(Att_Date) AS 'Date',
RTRIM(dbo.FormatDateTime(Att_Time,'HH:MM:SS 12')) AS 'Time',
RTRIM(dprj.Proj_Name) AS 'Day Site', RTRIM(nprj.Proj_Name) AS 'Noon Site',
RTRIM(ISNULL(Proj_Status,'::::')) AS 'Status', RTRIM(ISNULL(DA_Alloted,0)) AS 'DA'
FROM tb_attendance att, tb_employee emp, tb_project_list dprj, tb_project_list nprj
WHERE att.Att_Date = dbo.gefgChar2Date(@OrderDate)
Before Execute the Function
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[gefgChar2Date]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[gefgChar2Date]
GO
CREATE Function gefgChar2Date(@dt Char(10))
returns Char(11)
With Encryption
as
Begin
Declare @res char(11)
if (@dt = NULL or Ltrim(Rtrim(@dt)) = '') set @dt = NULL
Select @res = convert(char(11),convert(datetime,@dt,103),106)
return (@res)
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
[EDIT]Code tags added - LOSMAC[/EDIT]