c# - how to display date and time separately in grid view -
i have 1 column in sql table. name intime
. data type nvarchar
. stores both date , time. want date , time separately.
i have tried query:
select attendancedate, substring(convert(varchar,intime,113),1,11)[intime], substring(convert(varchar,intime,113),13,19)[intime], indeviceid, outtime, outtime, outdeviceid, dbo.minutestoduration(duration) duration, status dbo.attendancelogs employeeid=2938 order attendancedate desc
but if pass same sql command in grid view not working.
public void bind() { sqlcommand cmd = new sqlcommand("select attendancedate,substring(convert(varchar,intime,113),1,11) [intime],substring(convert(varchar,intime,113),13,19) [intime],indeviceid,outtime,outtime,outdeviceid, dbo.minutestoduration(duration) duration,status dbo.attendancelogs employeeid='" + empidtxt.text + "' , year(attendancedate)=" + ddlyear.selecteditem + " , month(attendancedate)=" + ddlmnt.selectedvalue + " order attendancedate desc", con); sqldataadapter da = new sqldataadapter(); cmd.connection = con; da.selectcommand = cmd; datatable dt = new datatable(); da.fill(dt); gridview1.datasource = dt; gridview1.databind(); gridview1.controlstyle.font.size = 10; }
where possibly problem?
replace code
public void bind() { sqlcommand cmd = new sqlcommand(@"select attendancedate,substring(convert(varchar,intime,113),1,11) [intimed],substring(convert(varchar,intime,113),13,19) [intimet], indeviceid,outtime,outtime,outdeviceid, dbo.minutestoduration(duration) duration,status dbo.attendancelogs employeeid='" + empidtxt.text + "' , year(attendancedate)=" + ddlyear.selecteditem.value + " , month(attendancedate)=" + ddlmnt.selectedvalue + " order attendancedate desc", con); sqldataadapter da = new sqldataadapter(cmd,con); datatable dt = new datatable(); da.fill(dt); gridview1.datasource = dt; gridview1.databind(); gridview1.controlstyle.font.size = 10; }
this line not filter year return object of drop down list
year(attendancedate)=" + ddlyear.selecteditem + "
Comments
Post a Comment