将访问表单中的数据添加到mysql数据库中 [英] Add data from access form into mysql database

查看:181
本文介绍了将访问表单中的数据添加到mysql数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有访问应用程序,允许用户添加帐户,目前程序添加,更新,删除链接的mdb表中的信息。我无法弄清楚的是如何添加一个到mysql数据库的链接,以便在mdb和mysql更新到最新的信息。



我创建了一个指向mysql表的链接(称为accounts1),并尝试添加代码来创建dao.recordset但是完全丢失了。



同样在我的插入查询中最后一个现场公司,在我的访问表单上我有复选框但在mysql表上有与每种类型的公司相关的数字,我如何转换标记为公司的复选框。 (例如,如果复选框标记为'Fed mutual',则公司在mysql数据库上被指定为'2')



我尝试了什么:



Hi, I have access application allowing users to add accounts, currently the program add,update,deletes information from a linked mdb table. What I can't figure out is how to also add a link to mysql database in order have information in both the mdb and mysql update-to-date.

I created a link to mysql table (called accounts1), and tried to add code to create a dao.recordset but am completely lost.

Also in my Insert query for the last field company, on my access form I have check boxes but on mysql table has numbers associated with each type of company, how do I converted the checkbox marked to a company. (for exmaple if checkbox is marked for 'Fed mutual' the company is assigned '2' on the mysql databse)

What I have tried:

<pre>Private Sub AddCmdButon_Click()
    
    ValidateCmdButton_Click
    
    If Me.ProcessFlagTBox = False Then
       Dim dbs1 As Database
       Dim aTable As Recordset
       Dim srchKey As String
       Set dbs1 = CurrentDb
       Set aTable = dbs1.OpenRecordset("Accounts", dbOpenDynaset)
       srchKey = "[ShortDescription] = '" & Me.ShortDescriptionTBox & "'"
       aTable.FindFirst srchKey
       
       Dim db As DAO.Database
       Dim rstAccounts As DAO.Recordset
       Dim strSQL As String
       Set db = CurrentDb
       strSQL = strSQL = INSERT INTO accounts1 ('ShortDesc', 'Description',     'Account', 'Region', 'CostCode', 'LOB', 'State', 'StateReq', 'NAICPLS', 'Company')
                VALUES ('UCase(Me.ShortDescriptionTBox)', 'UCase(Me.DescriptionTBox)', 'UCase(Me.MajorAccountTBox)', 'UCase(Me.DivRegionTBox)', 'UCase(Me.CostCodeTBox)',
                'UCase(Me.LOBTBox)', 'UCase(Me.StateTBox)', 'Me.[NAIC-PageLineSubLineTBox]', '????';
       Set rstAccounts = db.OpenRecordset(strSQL)
       
       If aTable.NoMatch = True Then
          ' Record not found (Add it)
          aTable.AddNew
          aTable![ShortDescription] = UCase(Me.ShortDescriptionTBox)
          aTable![Description] = UCase(Me.DescriptionTBox)
          aTable![MajorAccount] = UCase(Me.MajorAccountTBox)
          aTable![DivReg] = UCase(Me.DivRegionTBox)
          aTable![CostCenter] = UCase(Me.CostCodeTBox)
          aTable.Update
          MsgBox "The record was successfully added.", vbOKOnly, "INFORMATIONAL MESSAGE BOX"
          ClearCmdButton_Click
          Me.DescrComboBoxCBox.Requery
          Me.DescrComboBoxCBox1.Requery
         Else
          ' Record found (Duplicate)
          MsgBox "The record already exist on file. ", vbOKOnly, "INFORMATIONAL MESSAGE BOX"
       End If
       aTable.Close
       dbs1.Close
    End If
    

End Sub

推荐答案

Google:Access VBA create table link [ ^ ]


这不是c orrect vba语法

This is not correct vba syntax
strSQL = strSQL = INSERT INTO accounts1 ('ShortDesc', 'Description',     'Account', 'Region', 'CostCode', 'LOB', 'State', 'StateReq', 'NAICPLS', 'Company')
                VALUES ('UCase(Me.ShortDescriptionTBox)', 'UCase(Me.DescriptionTBox)', 'UCase(Me.MajorAccountTBox)', 'UCase(Me.DivRegionTBox)', 'UCase(Me.CostCodeTBox)',
                'UCase(Me.LOBTBox)', 'UCase(Me.StateTBox)', 'Me.[NAIC-PageLineSubLineTBox]', '????';



这也不是一个正确的sql语句。

SQL Tutorial [ ^ ]

SQL INSERT INTO语句 [< a href =https://www.w3schools.com/sql/sql_insert.asptarget =_ blanktitle =新窗口> ^ ]



据我了解,它也受SQL注入漏洞的影响。

永远不要通过连接字符串来构建SQL查询。迟早,您将使用用户输入来执行此操作,这会打开一个名为SQL注入的漏洞,这对您的数据库很容易并且容易出错。

名称中的单引号你的程序崩溃。如果用户输入像Brian O'Conner这样的名称可能会使您的应用程序崩溃,那么这是一个SQL注入漏洞,崩溃是最少的问题,恶意用户输入,并且它被提升为具有所有凭据的SQL命令。

SQL注入 - 维基百科 [ ^ ]

SQL注入 [ ^ ]

按示例进行SQL注入攻击 [ ^ ]

PHP:SQL注入 - 手册 [ ^ ]

SQL注入预防备忘单 - OWASP [ ^ ]

我该怎么办?解释没有技术术语的SQL注入? - 信息安全堆栈交换 [ ^ ]


And this is not a correct sql statement either.
SQL Tutorial[^]
SQL INSERT INTO Statement[^]

And as I understand it, it is also subject to SQL injection vulnerability.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]


这篇关于将访问表单中的数据添加到mysql数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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