无法将数据从SQL Server插入Access [英] Fail to insert data into Access from SQL Server

查看:71
本文介绍了无法将数据从SQL Server插入Access的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法将数据插入Access

Fail to insert data into Access

Function selectDB17()
Dim cn As New SqlConnection
Dim cmd As New SqlCommand

cn.ConnectionString = ("server=EKS-HQ;database=BGB;user id=administrator;password=admineks2005")
cn.Open()
cmd.Connection = cn
cmd.CommandText = "SELECT KODSTATE,USERID,PASSWORD,KUMPULAN FROM USERID"
Dim lrd As SqlDataReader = cmd.ExecuteReader()
Try
Do While lrd.Read()
If lrd.HasRows Then
a = lrd("KODSTATE")
b = lrd("USERID")
c = lrd("PASSWORD")
d = lrd("KUMPULAN")
Else
MsgBox("Tiada Data")
End If
insertDB17()
Loop
Catch ex As Exception
MessageBox.Show("Error while retrieving records on table..." & ex.Message, "Load Records")
Finally
cn.Close()
End Try

End Function
Function insertDB17()
Dim con As OleDb.OleDbConnection
Dim str As String
Dim cmd As OleDb.OleDbCommand
Try
con = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OleD b.4.0;data source=" & strsaveDB & "\" & strnameDB & ".mdb")
con.Open()
str = "insert into USERID(KODSTATE,USERID,PASSWORD,KUMPULAN)values(''" & a & "'' ,''" & b & "'',''" & c & "'',''" & d & "'')"
cmd = New OleDb.OleDbCommand(str, con)
cmd.ExecuteNonQuery()
Catch
End Try
con.Close()
End Function



===============================================
你好呀.有人知道我的代码有什么问题吗?我无法在Access中的表USERID中插入.实际上,在此之前,我已经使用了相同的代码插入并成功.



=================================================
Hi there. Does anyone know what''s wrong with my code. I fail to insert in table USERID in Access. Actually, I''ve use the same code to insert before this and it succeeded.

推荐答案

如果我是你,我会尝试删除try/赶上insertDB17.现在,您可能会遇到错误,但是您可以忽略它...
If I were you, I''d try to remove the try/catch in insertDB17. As it is now, you might be getting an error, but you just ignore it...


在这种情况下,我很想做的一个步骤是在您的计算机上放置一个断点str =插入..."

从快速的观察中,我会将您的程序已创建的sql语句复制并粘贴到access中,并尝试在那里执行该语句

这会导致任何错误吗?

由于必须停止插入工作
in that case one step that what I would be tempted to do is put a breakpoint on your str = "insert..."

from a quick watch i would copy and paste the sql statement that your program has created into access and try to executing the statement there

does this cause any errors?

As something has to be stopping the insert work


这篇关于无法将数据从SQL Server插入Access的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆