|
查看: 1057|回复: 3
|
vb.net (Date Problem)
[复制链接]
|
|
|
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If (objcon.con_master.State = ConnectionState.Closed)
Then objcon.con_master.Open()
Dim cmd As New OleDbCommand("insert into m_test (aa,date) values ('erer',#" & IIf(IsDate(TextBox1.Text), TextBox1.Text, DBNull.Value) & "#)", objcon.con_master)
cmd.ExecuteNonQuery()
End Sub
我要pass NULL value进DATE field, by access database.
but got error message
"Syntax error in date in query expression '##'."
请问要如何pass NULL into date field??
thanks all |
|
|
|
|
|
|
|
|
|
|
发表于 8-1-2009 11:28 AM
|
显示全部楼层
回复 1# Fly_Fish 的帖子
改成这样吧:
Dim cmd As New OleDbCommand("insert into m_test (aa,date) values ('erer'," & IIf(IsDate(TextBox1.Text), "#" & TextBox1.Text & "#", DBNull.Value))",
不过最好还是用parameterized query。要注意日期的格式,这样子很容易引来error。 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 8-1-2009 12:03 PM
|
显示全部楼层
my code:
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If (objcon.con_master.State = ConnectionState.Closed) Then objcon.con_master.Open()
Dim cmd As New OleDbCommand("insert into m_test (aa,dd) values ('erer'," & IIf(IsDate(TextBox1.Text), "#" & TextBox1.Text & "#", DBNull.Value), objcon.con_master)
cmd.ExecuteNonQuery()
End Sub
but still error:
"Syntax error in INSERT INTO statement."
 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 8-1-2009 12:28 PM
|
显示全部楼层
problem solve...........
thanks |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|