|
-
Jun 19th, 2001, 01:45 AM
#1
Using Data Environment
Hey peeps,
Im trying to learn how to use the database environment ccreator in VB. I am used to using the ado recordset and binding with code. No i am usind the database environment creator to bind and connect to thr database . The problem is, i can use commands like .movenext and .moveprevious etc but i cant .update or .addnew wont work. I have linked 2 tables on the same form so i duno if thats the problem. I just want to be able to add , delete and edit my database files through my vb application. I tried using sql but its not working . Any Suggestions?
-
Jun 19th, 2001, 07:47 AM
#2
Lively Member
Give us a sample of your code that doesn't work. I mean the speciffic fragment of your code when you try to update or add and it doesn't do the trick. Maybe then we'll be able to provide you with some hints.
Surgeon
-
Jun 19th, 2001, 10:19 AM
#3
Heres my code
Ok , Heres some of my code. But first i need to list some facts.
1. DataEnvironment is the default dataenvironment1. For some reason , when i try to change the name, i lose the binding to my text boxes.
2. I have one command called Guest which links to the guest table and the reservation table which is a child command of guest.
Both these tables are linked and shown on the same form.
3. NOne of these work except the next and previous buttons
4. The dataEnvironment binds my text boxes and opens my connection
Private Sub CmdNext_Click()
'*****************************************
'Moves to the next record in the database
'*****************************************
With DataEnvironment1.rsGuest
.MoveNext
If .EOF Then
.MoveFirst
End If
End With
End Sub
Private Sub CmdPrevious_Click()
'*****************************************
'Moves to the previous record in the database
'*****************************************
With DataEnvironment1.rsGuest
.MovePrevious
If .BOF Then
.MoveLast
End If
End With
End Sub
Private Sub CmdSave_Click()
Dim intResponse As Integer
Do Until ActiveControl.TabIndex >= CmdSave.TabIndex
SendKeys vbTab
DoEvents
If mblnbadData = True Then Exit Sub
Loop
intResponse = MsgBox("Are you sure?", vbYesNo + vbQuestion, "Canaveral Breakers Hotel")
If intResponse = vbYes Then
DataEnvironment1.rsGuest.Update
DataEnvironment1.rsGuest.MoveFirst
DataEnvironment1.rsGuest.Requery
Else
MsgBox "Record Was Not Saved", vbInformation, "Canaveral Breakers Hotel"
End If
CmdAdd.Enabled = True
CmdNext.Enabled = True
CmdPrevious.Enabled = True
CmdClose.Enabled = True
CmdDelete.Enabled = True
CmdInvoice.Enabled = True
Exit Sub
End Sub
Private Sub CmdClear_Click()
'********************************************
'Clears the information displayed in the form
'********************************************
With DataEnvironment1.rsGuest
If .EditMode = adEditAdd Then
.CancelUpdate
CmdAdd.Enabled = True
CmdNext.Enabled = True
CmdPrevious.Enabled = True
CmdClose.Enabled = True
CmdDelete.Enabled = True
CmdInvoice.Enabled = True
Else
.MoveLast
End If
End With
End Sub
Private Sub CmdAdd_Click()
'*****************************************
'Adds new record to the database
'*****************************************
DataEnvironment1.rsGuest.AddNew
'Make sure all textbokes are validated before proceeding
txtGuestNo.SetFocus
CmdAdd.Enabled = False
CmdNext.Enabled = False
CmdPrevious.Enabled = False
CmdClose.Enabled = False
CmdSave.Enabled = True
CmdDelete.Enabled = False
CmdInvoice.Enabled = False
CmdClear.Enabled = True
End Sub
Private Sub CmdDelete_Click()
'****************************
'Deletes Record
'****************************
Dim intResponse As Integer
intResponse = MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion, "Canaveral Breakers Hotel")
If intResponse = vbYes Then
With DataEnvironment1.rsGuest
If .RecordCount = 1 Then
.Delete
.MoveFirst
MsgBox "No Record in Database", vbInformation, "Canaveral Breakers Hotel"
CmdSave.Enabled = False
CmdNext.Enabled = False
CmdPrevious.Enabled = False
CmdClear.Enabled = False
CmdDelete.Enabled = False
CmdInvoice.Enabled = False
Else
.Delete
.MoveFirst
End If
End With
Else
MsgBox "Record Was Not Deleted", vbInformation, "Canaveral Breakers Hotel"
End If
DataEnvironment1.rsGuest.MoveFirst
Exit Sub
End Sub
-
Jun 19th, 2001, 10:21 AM
#4
Hyperactive Member
i was using data environment recently, but i had so many problems that i resolved give up
i recomend for you to use the recordset object
If you want to be loved, first love who God gave to you.
"Se você quer ser amado, primeiro ame quem Deus te deu"
(Acts 20:35)
-
Jun 19th, 2001, 05:04 PM
#5
Hyperactive Member
What is the error you get when you try to delete or add a record?
-
Jun 19th, 2001, 09:07 PM
#6
Addicted Member
Ran into this one myself a while ago. If you use the Command object to execute your query, the recordset will be read only and some of the move commands will result in errors. Dont know if this was intended or just an ADO glitch. In any event, after about a year working with ADO, I have not come across one single reason to use the Command object in code as opposed to the recordset object. As an aside, if you use the Data Environment and reference the command object, it will work fine. Seems to only be a glitch in the Active X Data Object Library. There are many posts here about this.
Shawn Hull
VB6, SP3 (Professional Edition)
-
Jun 19th, 2001, 11:27 PM
#7
I Give up !!! Another problem
Hey guys,
Thanks for all your help . I think im gonna take your advice and just link via code and not use the data environment. I am however having another problem, See i have two fields in two different tables that are linked . The problem is the parent table field is auto number so when i update the record the related field in the child table doesnt get updated cause the field in the parent field doesnt have a value until after you update. I dunno if im explaining this right but i hope someone can help. ThANKS AGAIN
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|