Searching Between two Values

xXProjectXx

Member
Joined
Apr 7, 2014
Messages
11
Programming Experience
Beginner
Hi all,

If it's possible I need some help about the program I'm creating in vb.net.. I have a DataGridView on my form and it's got a bindingsource to my MSSQL Database where I store all my values, on the form I also Have 2 TextBox because all I want to do is this:

If a person insert for example: 1.500 in the 1st TextBox and 1.700 in the second I want The DataGrid to show me the results between those numbers in the column named "Money".. My code is this (but when I insert the values the DataGrid just goes blank and I tried all type of syntax):

Thank you for the Help, I wish you all the best!


MoneyBindingSource.Filter = String.Format ("Money" >= TextBox1.Text And "Money" <= TextBox2.Text)




 
Do you want store just the date, just the time or both the date and time? It would appear that you want to store just the time so why would you change the data type to datetime? I ask again:
Did you do as I suggested and view the result of my code from post #12? What did you deduce about the required format? What did you then try? It's an odd format but not hard to reproduce.
 
Dim table As New DataTable
table.Columns.Add("[Enter Time]", GetType(TimeSpan))
table.Columns.Add("[Exit Time]", GetType(TimeSpan))
table.Columns.Add("Text", GetType(String), "CONVERT(Time, 'System.String')")

For i = 1 To 30
table.Rows.Add(TimeSpan.FromHours(i))
Next

Me.moneybindingsource.DataSource = table
Me.DataGridView1.DataSource = Me.moneybindingsource

In this way it doesn't work, I also tried to get rid of the "Time" gettype string column 'cause obviously the program say that Text column doesn't exist and it shows lot of blank rows in my dgv. Surely I'm missing a piece of comparison..
 
You might try actually reading what I posted. The code I provided was for you to try EXACTLY AS IS to see what format the Strings need to be in for you to compare to the TimeSpans in your DataTable. It was not code to fix your problem. It was code for you to see what you needed to do to fix your problem.
 
Yes I know that wasn't the code I was just wondering why loop through a datatable when there is a bindingsource for a timespan, anyway I was "forced" by someone to put columns as datetime and show on my dgv only the time format (I formatted the time columns in 't') but when i save the time "example 07:00 as enter time in museum and 09:00 for exit time" in SQL it stores as "2014-04-14 09:00:00.000" Now that's not the problem since I can view it on my dgv as "09:00" the problem is that I need the date portion to be set in a value like "1900-01-01" and no as current date because when a new day starts over the filter doesn't work anymore (I guess because I go filtering same times but with a different date and if I can't see it on my dgv on my database it's there). Thank you for your relpy
 
Back
Top