Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to solve this? i got this error when i running my code.

can someone help me? Thank you in advance. :D

to do coding renew thesis
   Private Sub renewBtn_Click(sender As Object, e As EventArgs) Handles renewBtn.Click

       ' Dim cmdupdate As OleDbCommand = New OleDbCommand

       If idsearchtxt.Text <> "" Or namerenewl.Text <> "" Or Lemail.Text <> "" Or icNoRenew.Text <> "" Or codeLabel.Text <> "" Or renewTitleL.Text <> "" Or authorRenew.Text <> "" Or yearRenew.Text <> "" Or renewDtp.Text <> "" Or renewDue.Text <> "" Then
           Convert.ToInt32(yearRenew.Text)
           Try
               Me.BorrowThesisTableAdapter.Insert(idsearchtxt.Text, namerenewl.Text, Lemail.Text, icNoRenew.Text, codeLabel.Text, renewTitleL.Text, authorRenew.Text, yearRenew.Text, renewDtp.Text, renewDue.Text)
               Me.BorrowThesisTableAdapter.Fill(Me.ThesisDBDataSet.BorrowThesis)
               Me.BorrowThesisTableAdapter.Update(Me.ThesisDBDataSet.BorrowThesis)

           Catch ex As Exception
               MsgBox(ex.Message)

           End Try
       Else
           MsgBox("Please fill the borrow info before you save.", MsgBoxStyle.Information)

       End If

   End Sub
Posted
Comments
Sergey Alexandrovich Kryukov 24-Dec-13 11:32am    
"BorrowThesis"... how modest!
—SA
missBlank 25-Dec-13 4:41am    
modest? hahaha

1 solution

I think you probably mean "And" rather than "Or"...
VB
If a Or b Or c Then
   Execute("this statement if any one is true")
End If
So is a is true, the statement will be executed, without even looking at b or c
On the other hand:
SQL
If a And b And c Then
   Execute("this statement if all of them are true")
End If
Then a must be true, and b must be true, and c must be true.
So in your existing code, if (for example) idsearchtxt.Text is not an empty string, then it will try to convert yearRenew.Text to an integer, even if it is an empty string.
Try changing all your "Or"s to "And"s and see if the problem goes away.
 
Share this answer
 
Comments
missBlank 24-Dec-13 9:38am    
i have change it to And.. but, when i run the program.. it automatically do the else statement.
it display this message

Else
MsgBox("Please fill the borrow info before you save.", MsgBoxStyle.Information)
OriginalGriff 24-Dec-13 9:43am    
Then at least one of your textboxes is empty!
So put a breakpoint on the If line, and check the contents - look for which is empty and decide if you meant to check it.

You should really use Int32.TryParse instead of Convert because the Convert will still fail if the user enters "Hello" instead of a number. TryParse returns a bool to say if the conversion succeeded or not.
missBlank 25-Dec-13 4:54am    
no sir. it is not empty. all the textbox is filled before i clicked the update button. please sir, help me.. the new error occur is this "Additional information: Conversion from string "" to type 'Integer' is not valid."
OriginalGriff 25-Dec-13 6:17am    
As I said - put a breakpoint on it and have a look at the strings.

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