Click here to Skip to main content
15,882,388 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi, 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
Posted
Updated 1-Apr-17 10:55am
v2

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900