我有sql的问题
我想选择那些费用的所有因素< 1 mounth前
我的代码:
Private Sub ShowData()
Dim dtToday As DateTime = Date.Today
dtToday = dtToday.AddMonths(-1)
DataGridView1.RowTemplate.Height = 30
DataGridView1.Font = New Font("Arial", 10, FontStyle.Regular)
conn.Open()
If conn.State = ConnectionState.Open Then
conn.Close()
End If
With cmd
.Connection = conn
.CommandText = "select f_id,f_recno,f_name,f_workout,f_feesmode,f_fees,f_feesdate from
tbl_memberfees where f_feesdate > " & Date.Today.AddMonths(-1) & ""
End With
da.SelectCommand = cmd
dt.Clear()
da.Fill(dt)
DataGridView1.DataSource = dt
conn.Close()
datagridviewcontrol()
End Sub
答案 0 :(得分:-1)
试试这个...因为您将数据存储在SQL中作为varchar。您应该在SQL中进行转换。
Private Sub ShowData()
Dim dtToday As DateTime = Date.Today
dtToday = dtToday.AddMonths(-1)
DataGridView1.RowTemplate.Height = 30
DataGridView1.Font = New Font("Arial", 10, FontStyle.Regular)
conn.Open()
If conn.State = ConnectionState.Open Then
conn.Close()
End If
With cmd
.Connection = conn
.CommandText =
"selectf_id,f_recno,f_name,f_workout,f_feesmode,f_fees,f_feesdate
from tbl_memberfees
where CONVERT(DATETIME, f_feesdate , XXX)> " & Date.Today.AddMonths(-1) & ""
End With
da.SelectCommand = cmd
dt.Clear()
da.Fill(dt)
DataGridView1.DataSource = dt
conn.Close()
datagridviewcontrol()
End Sub
其中XXX是以字符串形式存储的日期的当前格式。