向Access插入数据后显示INSERT INTO语法错误!!!
我用的是ASP.NET(VB)+ACCESS技术SubSave_Click(ByValsenderAsObject,ByValeAsEventArgs)DimCnnAsO...
我用的是ASP.NET(VB)+ACCESS技术
Sub Save_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim Cnn As OleDbConnection
Dim Cmd As OleDbCommand
Dim DataR As OleDbDataReader
Dim strConn, Sql, theNo As String
Dim i As Integer
Dim subdateStr As String = subdate.Text
Dim czyStr As String = czy.Text
Dim bzStr As String = bz.Text
theNo = Right(Year(Now), 2) & Format(Month(Now), "00") & Format(Day(Now), "00")
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("~\database\ck.mdb")
Cnn = New OleDbConnection(strConn)
Cnn.Open()
Sql = "select * from rk where left(rk_id,6)='" & Trim(theNo) & "' order by rk_id desc"
Cmd = New OleDbCommand(Sql, Cnn)
DataR = Cmd.ExecuteReader
If DataR.Read() Then
theNo = Trim(theNo) & Trim(Format(CInt(Right(DataR("rk_id").ToString, 3)) + 1, "000"))
Else
theNo = theNo & "001"
End If
DataR.Close()
For i = 0 To cart1.Rows.Count - 1
Dim NoStr As String = cart1.Rows(i)(0)
Dim purdateStr As String = cart1.Rows(i)(1)
Dim supfnamestr As Single = cart1.Rows(i)(2)
Dim purnamestr As Single = cart1.Rows(i)(3)
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
strConn = strConn & Server.MapPath("~\database\ck.mdb")
Cnn = New OleDbConnection(strConn)
Cnn.Open()
Sql = "insert into rk(rk_id,purid,purdate,supfname,purname,subdate,czy,bz) values('" & theNo & "','" & NoStr & "','" & purdateStr & "','" & supfnamestr & "','" & purnamestr & "','" & subdateStr & "','" & czyStr & "','" & bzStr & "')"
Cmd = New OleDbCommand(Sql, Cnn)
Cmd.ExecuteNonQuery()
Next
Page.RegisterStartupScript("", GetAlertInfo("数据提交成功!"))
cart1.Clear()
Response.Redirect("cgdcx.aspx")
End Sub
没有.所有字段的类型都是文本形式.
还有一段代码错误类型是一样的.
如下:
Sql = "insert into ckd(ck_id,fhorder_id,fhorder_clientname,fhorder_salesman,fhorder_kdtime,fhorder_fhtime,fhorder_status,fhorder_remake,date,czy,bz) values('" & theNo & "','" & NoStr & "','" & clientnameStr & "','" & salesmanstr & "','" & kdtimestr & "','" & fhtimestr & "','" & statusstr & "','" & remakestr & "','" & dateStr & "','" & czyStr & "','" & bzStr & "')" 展开
Sub Save_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim Cnn As OleDbConnection
Dim Cmd As OleDbCommand
Dim DataR As OleDbDataReader
Dim strConn, Sql, theNo As String
Dim i As Integer
Dim subdateStr As String = subdate.Text
Dim czyStr As String = czy.Text
Dim bzStr As String = bz.Text
theNo = Right(Year(Now), 2) & Format(Month(Now), "00") & Format(Day(Now), "00")
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("~\database\ck.mdb")
Cnn = New OleDbConnection(strConn)
Cnn.Open()
Sql = "select * from rk where left(rk_id,6)='" & Trim(theNo) & "' order by rk_id desc"
Cmd = New OleDbCommand(Sql, Cnn)
DataR = Cmd.ExecuteReader
If DataR.Read() Then
theNo = Trim(theNo) & Trim(Format(CInt(Right(DataR("rk_id").ToString, 3)) + 1, "000"))
Else
theNo = theNo & "001"
End If
DataR.Close()
For i = 0 To cart1.Rows.Count - 1
Dim NoStr As String = cart1.Rows(i)(0)
Dim purdateStr As String = cart1.Rows(i)(1)
Dim supfnamestr As Single = cart1.Rows(i)(2)
Dim purnamestr As Single = cart1.Rows(i)(3)
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
strConn = strConn & Server.MapPath("~\database\ck.mdb")
Cnn = New OleDbConnection(strConn)
Cnn.Open()
Sql = "insert into rk(rk_id,purid,purdate,supfname,purname,subdate,czy,bz) values('" & theNo & "','" & NoStr & "','" & purdateStr & "','" & supfnamestr & "','" & purnamestr & "','" & subdateStr & "','" & czyStr & "','" & bzStr & "')"
Cmd = New OleDbCommand(Sql, Cnn)
Cmd.ExecuteNonQuery()
Next
Page.RegisterStartupScript("", GetAlertInfo("数据提交成功!"))
cart1.Clear()
Response.Redirect("cgdcx.aspx")
End Sub
没有.所有字段的类型都是文本形式.
还有一段代码错误类型是一样的.
如下:
Sql = "insert into ckd(ck_id,fhorder_id,fhorder_clientname,fhorder_salesman,fhorder_kdtime,fhorder_fhtime,fhorder_status,fhorder_remake,date,czy,bz) values('" & theNo & "','" & NoStr & "','" & clientnameStr & "','" & salesmanstr & "','" & kdtimestr & "','" & fhtimestr & "','" & statusstr & "','" & remakestr & "','" & dateStr & "','" & czyStr & "','" & bzStr & "')" 展开
2个回答
展开全部
rk_id 如果是自编编号的话,插入/更新数据的时候不能指定该字段的值,改为
Sql = "insert into rk(purid,purdate,supfname,purname,subdate,czy,bz) values('" & NoStr & "','" & purdateStr & "','" & supfnamestr & "','" & purnamestr & "','" & subdateStr & "','" & czyStr & "','" & bzStr & "')"
试试
--------
把错误信息说一下
一般这样的错误我是这样排查的,把Sql 的内容放到Access的查询中执行试试看行不行,第1次只插入第一个字段的值,第二次插入第1和2个字段的值,每次多加一个字段上去,总能找到错误的地方的。
Sql = "insert into rk(purid,purdate,supfname,purname,subdate,czy,bz) values('" & NoStr & "','" & purdateStr & "','" & supfnamestr & "','" & purnamestr & "','" & subdateStr & "','" & czyStr & "','" & bzStr & "')"
试试
--------
把错误信息说一下
一般这样的错误我是这样排查的,把Sql 的内容放到Access的查询中执行试试看行不行,第1次只插入第一个字段的值,第二次插入第1和2个字段的值,每次多加一个字段上去,总能找到错误的地方的。
金山毒霸
2024-10-31 广告
2024-10-31 广告
大部分系统错误,是因为某些DLL文件丢失造成的,比如未安装DirectX9或DirectX 9.0组件已损坏、缺少Visual C ++库、未安装.net库。解决方法如下:一、 手动解决方法1、先确定电脑操作系统是多少位的,现在的电脑一般都...
点击进入详情页
本回答由金山毒霸提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询