Hi Honeyjo,
Refer below stored procedure.
CREATE PROCEDURE [dbo].[usp_GetRecordbySurnamePMRefStatus]
(
@LastName nvarchar(50) = NULL,
@PMRef nvarchar(50) = NULL,
@RecordStatus nvarchar(100) = NULL
)
AS
BEGIN
SET NOCOUNT ON;
SELECT *
FROM [dbo].[Autopsybook]
Where (LastName = @LastName OR @LastName IS NULL)
AND (PMRef = @PMRef OR @PMRef IS NULL)
AND (ecordStatus = @RecordStatus OR @RecordStatus IS NULL)
END
GO
Code
Protected Sub btnsearch_OnClick(sender As Object, e As EventArgs) Handles btnsearch.Click
Using con As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("conString").ConnectionString)
Using cmd As SqlCommand = New SqlCommand("usp_GetRecordbySurnamePMRefStatus", con)
cmd.CommandType = CommandType.StoredProcedure
If Not String.IsNullOrEmpty(txtsearch.Text.Trim()) Then
cmd.Parameters.AddWithValue("@LastName", txtsearch.Text.Trim())
Else
command.Parameters.AddWithValue("@LastName", DBNull.Value)
End If
If ddlGridfilter.SelectedItem.Value > 0 Then
cmd.Parameters.AddWithValue("@PMRef", ddlGridfilter.SelectedItem.Text)
Else
command.Parameters.AddWithValue("@PMRef", DBNull.Value)
End If
If ddlstatussearch.SelectedItem.Value > 0 Then
cmd.Parameters.AddWithValue("@RecordStatus", ddlstatussearch.SelectedItem.Text)
Else
command.Parameters.AddWithValue("@RecordStatus", DBNull.Value)
End If
Using sda As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
sda.Fill(dt)
Me.gvEmployee.DataSource = dt
Me.gvEmployee.DataBind()
End Using
End Using
End Using
End Sub
For more details refer below link.