Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help with binding problem

Author  Topic 

new2this
Starting Member

16 Posts

Posted - 2008-10-10 : 16:30:03
I have a textbox (paymentAmount) binded to a database (sql server). When the database was designed the paymentAmount is smallMoney. When the user put an amount in the textbox other that an numeric amount, nothing happens. It seems to wait for the user to enter a numeric number. How come the rest of the code doesn't run until there is a numeric number entered?

the textbox for payment amount is: xPaymentsTextBox

Private Sub xSaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles xSaveButton.Click

Dim rowsAdded As Integer
Dim paymentAmount As Decimal
Dim isValid As Boolean = False

isValid = Decimal.TryParse(Me.xPaymentsTextBox.Text, paymentAmount)

If isValid = True Then
If Me.xTransactionDateDateTimePicker.Checked = True Then
Try
Me.TransactionsBindingSource.EndEdit()
rowsAdded = Me.TransactionsTableAdapter.Update(Me.DataSetAddPayment.Transactions)
If rowsAdded > 0 Then
MessageBox.Show("Your transaction has been added to the database.", _
"Transaction Added", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Close()
Else
MessageBox.Show("No transaction was added.", "Transaction Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.Close()
End If
Catch ex As NoNullAllowedException
MessageBox.Show("Not all required files have valid data.", "Data Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Catch ex As DataException
MessageBox.Show(ex.Message, ex.GetType.ToString)
Catch ex As SqlException
MessageBox.Show(ex.Number & ex.Message, ex.GetType.ToString)
End Try
Else
MessageBox.Show("Make sure the check box is checked for the transaction date", _
"Transaction Date Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.xTransactionDateDateTimePicker.Focus()
End If
Else
MessageBox.Show("Please enter a valid numeric amount for your payment", _
"Payment Amount Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.xPaymentsTextBox.Focus()
Me.xPaymentsTextBox.Clear()
End If
End Sub

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2008-10-10 : 17:21:19
I think that is a question for vb-forums?
There is no starting point in your post that looks like sql server problem.

Sorry
Webfred

Planning replaces chance by mistake
Go to Top of Page

hanbingl
Aged Yak Warrior

652 Posts

Posted - 2008-10-10 : 17:25:06
[/code]
Private Sub xSaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles xSaveButton.Click

Dim rowsAdded As Integer
Dim paymentAmount As Decimal
Dim isValid As Boolean = False

isValid = Decimal.TryParse(Me.xPaymentsTextBox.Text, paymentAmount) 'CHECKS IF XPAYMENTSTEXTBOX IS DECIMAL,
'IF NOT IT STAYS FALSE


If isValid = True Then 'CHECK IF isValid EQUALS 'True' IF NOT SKIP THE REST OF THE CODE UNTIL 'ELSE' PART
If Me.xTransactionDateDateTimePicker.Checked = True Then
Try
Me.TransactionsBindingSource.EndEdit()
rowsAdded = Me.TransactionsTableAdapter.Update(Me.DataSetAddPayment.Transactions)
If rowsAdded > 0 Then
MessageBox.Show("Your transaction has been added to the database.", _
"Transaction Added", MessageBoxButtons.OK, MessageBoxIcon.Information)
Me.Close()
Else
MessageBox.Show("No transaction was added.", "Transaction Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.Close()
End If
Catch ex As NoNullAllowedException
MessageBox.Show("Not all required files have valid data.", "Data Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
Catch ex As DataException
MessageBox.Show(ex.Message, ex.GetType.ToString)
Catch ex As SqlException
MessageBox.Show(ex.Number & ex.Message, ex.GetType.ToString)
End Try
Else
MessageBox.Show("Make sure the check box is checked for the transaction date", _
"Transaction Date Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.xTransactionDateDateTimePicker.Focus()
End If
Else 'THIS IS WHERE THE CODE WILL EXECUTE TO IF isValid IS 'False', IT SIMPLY CLEARS xPaymentsTextBox's TEXT
MessageBox.Show("Please enter a valid numeric amount for your payment", _
"Payment Amount Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.xPaymentsTextBox.Focus()
Me.xPaymentsTextBox.Clear()
End If
End Sub[/code]
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2008-10-10 : 17:30:56
Hi han!
And what is about the messagebox?
OP told that NOTHING HAPPENS.

Webfred

Planning replaces chance by mistake
Go to Top of Page

hanbingl
Aged Yak Warrior

652 Posts

Posted - 2008-10-10 : 18:16:52
nothing happened in the database perhaps...
Go to Top of Page
   

- Advertisement -