Run SQL Select query for date with date time picker in vb.net -


i working in microsoft visual studio 2013 windows desktop. using windows form applications sql end. creating schedule , need able search few of schedules columns smalldatetime data type. trying input date time clause not seem work. have tried in sql server management studio program no success. here code:

 msgbox(datetimepicker1.value.tostring("yyyy-mmy-dd"))     try         using conn1 new sqlconnection(connstring)             conn1.open()             using comm1 new sqlcommand("select col1, col2, col3, " _                     & "col4, col5, col6, col7, col8, " _                     & "col9, col10, col11, col12, " _                     & "col13, col14, col15, " _                     & "col16, col17, " _                     & "col18, col19, " _                     & "col20, col21 table1 left join table2 " _                     & "on table2.col2 = table1.col2 left join table3 on " _                     & "table2.col1 = table3.col2 left join table4 on " _                     & "table2.col5 = table4.col5 complete null" _                     & " , " _                     & "table1.col7 '@date%'", conn1)                 comm1.parameters.addwithvalue("@date", datetime picker.value.tostring("yyyy-mm-dd"))                 dim dt new datatable                 dim sql new sqldataadapter(comm1)                 sql.fill(dt)                 datagridview.datasource = dt             end using             conn1.close()         end using          call paint()      catch ex exception         msgbox(ex.tostring)      end try 

the statement meant strings. if col7 smalldatetime, should using sort of date comparison. since you're using like, guess column might contain time information , want records returned particular date. don't use smalldatetime, datetime columns, simple solution cast column date , compare date parameter passed datetime picker. of course assumes you're using sql server 2008 , above since date datatype didn't exist until then.

another solution update clause following assuming @date not contain time information.

table1.col7 >= @date , table1.col7 < dateadd(day, 1, @date) 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -