Click here to Skip to main content
15,890,897 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
VB
Dim constring As String = "dsn=mysql_tabel;database=db1;server=localhost;iud=root"
Dim con As New OdbcConnection(constring)
con.Open()

Dim query As String = "SELECT *FROM tbdata_reservasi WHERE tanggal_masuk >= @ST " 'AND tanggal_keluar <= @ET"

Dim startdate As DateTime = New DateTime(MonthCalendar1.SelectionStart.Year, MonthCalendar1.SelectionStart.Month, 1)
Dim Enddate As DateTime = startdate.AddMonths(1)

Dim cmd As New OdbcCommand(query, con)

cmd.Parameters.Clear()
'cmd.Parameters.AddWithValue("@ST", startdate)
'cmd.Parameters.AddWithValue("@ET", Enddate)
cmd.Parameters.Add("@ST", OdbcType.DateTime).Value = startdate
cmd.Parameters.Add("@ET", OdbcType.DateTime).Value = Enddate


What I have tried:

please help...my coding there is no respon....what wrong with my coding
Posted
Updated 25-May-23 5:19am
v2
Comments
Graeme_Grant 25-May-23 10:20am    
MySql db? What happens when you run the command in MySql Workbench app?
Joebpn1 25-May-23 10:44am    
yupz mysql db.....there is no respon when i run
Graeme_Grant 25-May-23 11:07am    
Not what I asked. Did you check the query in the MySql Workbench app before trying to use in your code???

Here is a link to the app: MySQL Workbench App Download[^]
Joebpn1 25-May-23 11:13am    
no i did not
Graeme_Grant 25-May-23 11:16am    
Well, I recommend that you do. It is the right tool for writing queries, especially when learning. Also recommend: MySQL Tutorial - Learn MySQL Fast, Easy and Fun.[^]

1 solution

So where's the line that actually executes the command? Something like
VB.NET
OdbcDataReader reader = cmd.ExecuteReader()

Or whatever you should have for your requirements...
 
Share this answer
 
Comments
Joebpn1 25-May-23 12:13pm    
Dim constring As String = "dsn=mysql_tabel;database=db1;server=localhost;iud=root"
Dim con As New OdbcConnection(constring)
con.Open()

Dim query As String = "SELECT *FROM tbdata_reservasi WHERE tanggal_masuk >= '@ST' AND tanggal_keluar <= '@ET'"

Dim startdate As DateTime = New DateTime(MonthCalendar1.SelectionStart.Year, MonthCalendar1.SelectionStart.Month, 1)
Dim Enddate As DateTime = startdate.AddMonths(1)

Dim cmd As New OdbcCommand(query, con)

'cmd.Parameters.Clear()
'cmd.Parameters.AddWithValue("@ST", startdate)
'cmd.Parameters.AddWithValue("@ET", Enddate)
cmd.Parameters.Add("ST", OdbcType.DateTime).Value = startdate
cmd.Parameters.Add("ET", OdbcType.DateTime).Value = Enddate

Dim dr As OdbcDataReader = cmd.ExecuteReader()

While dr.Read
Dim RoomNum_R As Integer = dr.GetInt32(1)
Dim start_date As DateTime = dr.GetDate(10)
Dim end_date As DateTime = dr.GetDate(11)

Dim startdate_c As Integer = start_date.Day
Dim enddate_c As Integer = end_date.Day
Dim room1 As Integer = RoomNum_R - 1
Dim totaldays As Integer = enddate_c - startdate_c


DG1(startdate_c, room1).Style.BackColor = Color.Red
For i = 1 To totaldays
DG1(startdate_c + i, room1).Style.BackColor = Color.Red

totaldays -= 1

Next
End While
Dave Kreskowiak 25-May-23 13:17pm    
If you're not getting any exceptions and the resultset you're getting back is empty, the database doesn't have anything that matches your WHERE clause conditions.

One minor thing that may be screwing things up is the single quotes around the parameters in your SQL statement. Try getting rid of them:
...WHERE tanggal_masuk >= @ST AND tanggal_keluar <= @ET
Joebpn1 26-May-23 1:29am    
i have try that before...and still no respond
Pete O'Hanlon 26-May-23 2:00am    
Try your query out in MySQL directly. If things don't work when you try them through your application, check the query in the actual database itself. Also, change the query to this:

SELECT * FROM tbdata_reservasi WHERE tanggal_masuk >= @ST AND tanggal_keluar <= @ET

Copy and paste that line in directly. You had quotes in your original query, and they weren't needed.

One final thought; what data types have you used in the database for tanggal_masuk and tanggal_keluar?
Dave Kreskowiak 26-May-23 18:13pm    
Again, if you're not getting an exceptions but the code is executing, it means you're getting a result set that doesn't contain any records because the data in the database doesn't match your WHERE expression. Either the parameters you're passing in are wrong, or your expectations are wrong.

Beyond that, there is nothing anyone can tell you that's going to fix this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900