Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have this query that i want to fill its result in a data table
VB
Dim datenow As Date = Date.Now.Date

        Dim sql As String = "SELECT DISTINCT cmp_user_id FROM tbl_campaign WHERE cmp_date =#" & datenow & "#"




i use this method to fill it in a data table :

VB
Public Shared Function ExecuteSelect(ByVal query As String) As DataTable
      Dim xx As DataTable = New DataTable()
      Using a1 As New OleDbDataAdapter(query, ConnectionString)
          a1.Fill(xx)
      End Using
      Return xx
  End Function


how could i fix the query or the method to fill the datatable so i could use each data returned alone thanks
Posted
Comments
ridoy 15-Aug-13 6:41am    
not clear.
ridoy 15-Aug-13 6:45am    
You should have a look at http://support.microsoft.com/kb/301216 and http://stackoverflow.com/questions/10844358/read-from-database-and-fill-datatable

1 solution

Hi

You have a problem in your query string please change your query:

VB
Dim datenow As Date = Date.Now.Date
 
        Dim sql As String = "SELECT DISTINCT cmp_user_id FROM tbl_campaign WHERE cmp_date =#" & datenow.ToString() & "#"


But I suggestion to you check the cmp_date data type from your database and be sure it is a DateTime after you should check the format of this field, for example if your cmp_date fields format at database is "dd/mm/yyyy" you should set this format on your datenow variable too ;)


Best Regards.
 
Share this answer
 
v2
Comments
[no name] 15-Aug-13 6:12am    
the cmp_date is date time but i didnt specify any format to it what format should i put the datrnow to read that
Aydin Homay 15-Aug-13 6:53am    
Hadi trace your code and check it datenow format and compare with your database field date format, they both of dates should be same format for example dd/mm/yyyy

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