Hi,
I am creating a dropdownbox for users to select such as Surname, Status, M number etc and then a search text box, so they can input what search they need.
for eg: They select Surname from drop down and put Thomas in search tet box and click ok. I want the form to show a grid of all records with that surname from sql server.
I also have another search criteria using searching between dates. I have a start date and an end date and a search button. The user wants to search for all records to show in a grid form for the selected start date and end date.
I tried the code for the start and end date and im getting a Fill: Selectcommand.Connection property has not been initialized.
Below are the VB and SQL stored procedure codes i have done.
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles btndatesearch.Click
Dim conn As String = ConfigurationManager.ConnectionStrings("Database_Connection_Lookups").ConnectionString
Dim sql As String = "usp_GetAutopsyrecordbetweendates"
Using cmd As SqlCommand = New SqlCommand(conn)
Using da As SqlDataAdapter = New SqlDataAdapter(cmd)
cmd.Parameters.AddWithValue("@date1", Convert.ToString(Me.txtstartdate.Text, New CultureInfo("en-GB")))
cmd.Parameters.AddWithValue("@date2", Convert.ToString(Me.txtenddate.Text, New CultureInfo("en-GB")))
Dim ds As DataSet = New DataSet()
da.Fill(ds)
GridView1.DataSource = ds
GridView1.DataBind()
End Using
End Using
SQL Stored Procedure
ALTER PROCEDURE [dbo].[usp_GetArbetweendates]
(
@date1 date,
@date2 date
)
AS
SET NOCOUNT ON;
Select * from [dbo].[Ab]
WHERE (PMDate between @date1 and @date2)
GO
Please advise.
Many Thanks
Merin