|
-
Apr 9th, 2004, 08:04 AM
#1
Thread Starter
Frenzied Member
Binding Manager & dataset - won't add record
I've got an untyped dataset with controls bound through code. The user can select a question number from a bound combobox, and the question number and question text are displayed in bound textboxes. This part works fine.
When I go to add a new record, the textboxes clear as they should. I enter a new question number and tab to the textbox for the question text. At this point, the text for the previously selected question (whose number is still displayed in the combobox) reappears. If I then change the text anyway and try to save, it tries to update the previously selected record instead of adding a new one. I think it has something to do with the position of the datset not being changed, although the bindingmanagerbase position is. This code is almost directly from chapter 6 in Murach's book, VB.Net database programming with ado.net. Thanks for any help.
VB Code:
Private Sub BindControls()
Try
txtQuestion.DataBindings.Add("Text", dsQuestion.Tables _
("QS"), "QText")
txtQuNum.DataBindings.Add("Text", dsQuestion.Tables _
("QS"), "Q#")
cboQuNum.DataSource = dsQuestion.Tables("QS")
cboQuNum.DisplayMember = "Q#"
Catch ex As Exception
MessageBox.Show(ex.Message, "Binding Controls")
End Try
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnAdd.Click
Try
bmbQuestion.AddNew()
SetButtons(False)
btnSave.Enabled = False
blnNewRow = True
txtQuestion.Clear()
txtQuNum.Clear()
txtQuNum.Focus()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error Adding Record")
End Try
End Sub
Private Sub cboQuNum_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles cboQuNum.SelectedIndexChanged
If Not blnLoading Then
bmbQuestion.Position = cboQuNum.SelectedIndex
SetButtons(True)
btnSave.Enabled = dsQuestion.HasChanges
txtQuNum.Focus()
End If
End Sub
-
Apr 12th, 2004, 10:37 AM
#2
Thread Starter
Frenzied Member
I figured out the problem, although not the solution.
One of the fields in the table is named Q#. This gives Access a problem when updating, inserting, etc. Even though Access allows that to be a field name, in the SQL it wants it surrounded by brackets, like [Q#], since the # sign is a problem. The .Net app, however, doesn't like that since it's looking for a field just plain named Q#.
I could change the field name in the table (did that in a test db, to QNum, and it ran fine). The problem with that is that there's about 60 db's, each with a 5 or 6 queries, 50 or 6 forms, 5 or 6 reports, a module or two, probably 4 or 5 user interface db's that I don't know about, and some compiled programs as well, etc, that may reference the field.
It would really be a lot easier to just work this out in the app instead.
-
Apr 12th, 2004, 11:59 AM
#3
Thread Starter
Frenzied Member
Ok, I've tried coding the commands with the commandbuilder and manually, as below.
If I use the command builder or build them manually w/o brackets, I get an error "Syntax error in Insert Into statement" (or Update statement, etc).
If I build them manually with brackets, I get the error "No value given for one or more required parameters". How can I get these to run? Thanks.
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
|