在MS Access 2007中添加数据 [英] Adding data in MS access 2007

查看:87
本文介绍了在MS Access 2007中添加数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MS access 2007中遇到了一些问题..




1)我无法将用户输入的数据发送到文本框中VB2008。
2)Access文件没有更新

3)我如何知道(确认)数据已被保存或存在错误。
4)当我插入' cmd.ExecuteNonQuery()'有一个错误状态您无法添加或更改记录,因为表'代码'中需要相关记录。
我不知道我的代码的哪一部分给了我问题。 。请帮助..





这是我的编码:






i have got some problems in MS access 2007..


1) i cannot send the data which the user key in into the textbox of VB2008.
2) the Access file is not updating
3) how can i know(confirm) that the data has been saved or there is an error in it..
4) when i insert 'cmd.ExecuteNonQuery()' there is an error which state "You cannot add or change a record because a related record is required in table 'Code'."
i do not know which part of my code is giving me problems..
pls help..
thanks
buz


this is my coding:



Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

    Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\user\Desktop\Baxter\BaxterOCR_new.mdb;Jet OLEDB:Database Password=12345;"

    Dim MySQL As String = "INSERT INTO Batch" & _

       "(BatchNo, BarCodeNo, OperatorID, CodeNo,ExpiryDate) VALUES " & "('" & txtBatchNo.Text & "','" & txtBarCodeNo.Text & "','" & txtOperatorID.Text & "','" & txtCodeno.Text & "','" & txtExpiryDate.Text & "')"

    Dim MyConn As New OleDbConnection(strConn)

    Dim cmd As New OleDbCommand(MySQL, MyConn)

    MyConn.Open()

    With cmd.Parameters

        .Add(New OleDbParameter("@BatchNo", txtBatchNo.Text))

        .Add(New OleDbParameter("@BarCodeNo", txtBarCodeNo.Text))

        .Add(New OleDbParameter("@OperatorID", txtOperatorID.Text))

        .Add(New OleDbParameter("@CodeNo", txtCodeno.Text))

        .Add(New OleDbParameter("@ExpiryDate", txtExpiryDate.Text))

    End With

    cmd.ExecuteNonQuery()

    MyConn.Close()



End Sub

推荐答案

我认为这只是一些有趣的代码,没有一个是重新盟友会用这个,对吧?

我不明白第一个问题,这段代码如何尝试将文本发送到文本框?

ExecuteNonQuery是否返回一个数字?如果没有发生,它将返回0,如果你更新了一行,则返回1,等等。

你的基本问题是你违反了你的SQL。我开始认为这是一个实际的商业项目,在这种情况下,这是一场彻头彻尾的灾难。你的代码没有任何想法或设计的迹象,是不安全的(如果我想,我可以擦除你的数据库,只需按下Add按钮),并且在很多方面都是一团糟。

核心问题是,您对数据库有约束,而您提供的代码编号与代码表中的条目不对应。

我建议与您的经理/老师/无论情况如何,并解释您不了解SQL,还需要接受一些培训,了解如何将项目按照标准创建可维护,可调试,可读的代码。
I assume this is just some code for fun, no-one is really going to use this, right ? I don't understand the first question, how does this code try to send text to a textbox ? Is ExecuteNonQuery returning a number ? It will return 0 if nothing happened, 1 if you updated a row, etc. your basic problem is that you're violating your SQL. I am starting to think this is an actual commercial project, in which case, it is an utter disaster. Your code shows no sign of any thought or design, is insecure ( I could erase your database if I wanted to, just by pushing that Add button ), and is a mess in many ways. The core issue is, you have a constraint on the database and the code number you're providing does not correspond to an entry in the code table. I'd suggest talking to your manager/teacher/whatever the situation is and explaining that you don't understand SQL and also need some training in how to generally lay out a project to a standard that creates maintainable, debuggable, readable code.


这篇关于在MS Access 2007中添加数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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