我有問題,SQL如何選擇所有memeber vb.net
我想選擇所有memeber有feesdate是< 1個芒斯前
我的代碼:
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
***數據類型是f_feesdate ***?我還建議添加參數,因爲你的'sql'語法也是錯誤的......你需要'''在你的日期周圍。如果你有參數,這不會是一個問題......在另一個說明中,'feesdate <1個小時前'您的查詢是錯誤的。 'f_feesdate>''應該是'f_feesdate <'如果你想要它不到一個月前,目前這是更大的... – Codexer
類型f_feesdate是文本..可以halp或作小例 – amine02
我強烈建議進行更改到該列的日期時間/日期列數據類型***否則***您需要轉換或將其轉換爲正確的類型以進行比較......考慮到這一點,您可以在其中存儲任何內容,請考慮關於你的數據類型。我會強烈搜索谷歌關於這個以及使用參數。當你以正確的方式得到這個關於構建你的查詢的理解工作... – Codexer