SELECT with parameters

goran

New member
Joined
May 1, 2007
Messages
3
Programming Experience
Beginner
this shouldn't be hard to do but still i don't know it. i'm trying to show data in grid based on date selected in datetimepicker.
My code:

Private Sub kalendar_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kalendar.ValueChanged

Const dbCS As String = "Data Source=GORAN;Initial Catalog=dentist;Integrated Security=True"

Dim dbCN As New SqlClient.SqlConnection(dbCS)

Try
dbCN.Open()
Dim cmd As New SqlClient.SqlCommand

With cmd
.Connection = dbCN
.CommandType = CommandType.Text

Dim param As SqlClient.SqlParameter = cmd.Parameters.Add("@datum", SqlDbType.DateTime)

Dim da As New Data.SqlClient.SqlDataAdapter
param.Value = kalendar.Value.Date

.CommandText = ("SELECt CONVERT(varchar, posjeti.datum_posjeta, 108) AS Vrijeme, pacijent.prezime, pacijent.ime, zahvati.naziv_zahvata, zahvati.trajanje FROM pacijent INNER JOIN posjeti ON pacijent.ID_pacijenta = posjeti.ID_pacijenta INNER Join zahvati ON posjeti.ID_zahvata = zahvati.ID_zahvata WHERE (posjeti.datum_posjeta IN @datum")

da.SelectCommand = cmd
da.Fill(DentistDataSet.DataTable1)
dg1.DataSource = da
End With
Catch ex As Exception
MsgBox(Err.Description)
End Try


End Sub
 
aside from the fact that you probably cannot use a parameter as the target of an IN (it's a list of values, and a parameter is a single value) you wouldnt be writing code in your form anyway

Read the DW2 link in my signature, first read "Creating a simple app" (because it seems youre not familiar with the modern way of data access) and then read "Creating a form to search data"
 
Back
Top