1 Public Class Test
2 Private myConnStr As String = "data source=(local); integrated security=SSPI; initial catalog=CMI"
3
4 Public Function MakeDataTable(ByVal doc As Integer, ByVal thisDate As DateTime) As DataTable
5 ' Using
6 Dim connection As SqlConnection = New SqlConnection(myConnStr)
7 Try
8 Dim Query As String = "SELECT horainicio FROM [Modulo] WHERE idespecialidadmedico=@doc and iddia=@iddia"
9 Dim command As SqlCommand = New SqlCommand(Query, connection)
10 command.CommandType = CommandType.Text
11 command.Parameters.Add("@Doc", SqlDbType.Int).Value = doc
12 command.Parameters.Add("@iddia", SqlDbType.Int).Value = thisDate.Date.DayOfWeek
13 connection.Open()
14 Dim reader As SqlDataReader = command.ExecuteReader
15 Dim dt As DataTable = New DataTable("Result")
16
17 dt.Columns.Add("Hour", GetType(DateTime))
18 dt.Columns.Add("State", GetType(String))
19
20 While reader.Read
21
22 If IsReserved(doc, reader("Hour"), thisDate) Then
23 dt.Rows.Add(New Object() {reader("Hour"), "Reserved"})
24 Else
25 dt.Rows.Add(New Object() {reader("Hour"), "Available"})
26 End If
27
28 End While
29 dt.AcceptChanges()
30 Return dt
31 Finally
32 CType(connection, IDisposable).Dispose()
33 End Try
34 End Function
35
36 Public Function IsReserved(ByVal thisdoc As Integer, ByVal hour As DateTime, ByVal xDate As DateTime) As Boolean
37 Dim Query As String = "SELECT * FROM [RESERVA] WHERE idespecialidadmedico=1 AND fechareserva=@Date AND hireserva=@Hour"
38 ' Using
39 Dim connection As SqlConnection = New SqlConnection(myConnStr)
40 Try
41 Dim command As SqlCommand = New SqlCommand(Query, connection)
42 command.CommandType = CommandType.Text
43 command.Parameters.Add("@Doc", SqlDbType.Int).Value = thisdoc
44 command.Parameters.Add("@Date", SqlDbType.DateTime).Value = xDate
45 command.Parameters.Add("@Hour", SqlDbType.DateTime).Value = hour
46 connection.Open()
47 Dim reader As SqlDataReader = command.ExecuteReader
48 Dim isthere As Boolean = reader.HasRows
49 Return isthere
50 Finally
51 CType(connection, IDisposable).Dispose()
52 End Try
53 End Function
54 End Class
I've changed what you said, but I still have the same error :(
I think that can be the date format, 'cause when I make a query I make it like this
select * from reserva
where fechareserva = '2006-12-20'
So, I think it can be causing a conflict :S