VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 307,172 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,567 people online right now. Registration is fast and FREE... Join Now!




Try/Catch Problems

 

Try/Catch Problems

khulood Abdullah

10 Jan, 2009 - 07:16 AM
Post #1

New D.I.C Head
*

Joined: 19 Dec, 2008
Posts: 5


My Contributions
Hi all!!
I am trying to connect my code to a database and insert a value using ID as a way to access but when compiling, the catch part always shows up, If any body can give me a hint for that, here is the code,


CODE
Private Sub btnSumit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSumit.Click
        Dim intId As Integer
        Dim strAnswer As String = comboCountry.Text
        If strAnswer = strCountry Then
            lblAnswer.Text = "Correct!!"
            intPassCount += 1
        Else
            lblAnswer.Text = "Wrong Answer!! Hard Luck!!"

        End If

        If intCount >= 5 Then
            lblAnswer.Text = "Your Quiz is done!!"
            btnNext.Enabled = False
            comboCountry.Enabled = False
            If intPassCount >= 3 Then
                boolPass = True
                MessageBox.Show("Congratulations, You have Passed the Quiz!!, Your Score is " _
                                + intPassCount.ToString() + " out of 5")
                lblPass.Text = "Passed"
            Else
                boolPass = False
                MessageBox.Show("Unfortunately, You have Failed the Quiz!!, Your Score is " _
                                + intPassCount.ToString() + " out of 5")
                lblPass.Text = "Failed"

            End If
        Else
            btnNext.Enabled = True

        End If
        If intCount >= 5 Then
            Try
                Integer.TryParse(InputBox("Please Enter Your ID"), intId)
                Dim connStr As New OleDb.OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;" & _
                                "Data Source = StudentsGrades.mdb")
                connStr.Open()
                Dim sqlStr As String = ("INSERT INTO StudentsInfo(Score, Pass)VALUES('" & intPassCount.ToString & "','" _
                                        & lblPass.Text & "') SELECT Score, Pass FROM(StudentsInfo)WHERE ID = ' " & intId.ToString & "';")

                Dim dataAdapter As New OleDb.OleDbDataAdapter(sqlStr, connStr)
                dataAdapter.Fill(dt)
                dataAdapter.Dispose()

                MessageBox.Show("The information has been added successfuly")
                connStr.Close()
            Catch ex As Exception
                MessageBox.Show("The information already here!!")
            End Try
        End If
        btnSumit.Enabled = False



    End Sub


Your help is most appreciated!!
[color=#993399]

User is offlineProfile CardPM
+Quote Post


skyhawk133

RE: Try/Catch Problems

10 Jan, 2009 - 07:20 AM
Post #2

Head DIC Head
Group Icon

Joined: 17 Mar, 2001
Posts: 16,883



Thanked: 156 times
Dream Kudos: 1650
Expert In: Web Development

My Contributions
I've renamed your topic to "Try/Catch Problems". Per the rules, we require you to name your topic with a descriptive title.

Thank you for your cooperation.
User is offlineProfile CardPM
+Quote Post

AdamR

RE: Try/Catch Problems

10 Jan, 2009 - 07:45 AM
Post #3

D.I.C Head
**

Joined: 23 Sep, 2008
Posts: 144



Thanked: 7 times
My Contributions
Change the catch exception msgbox to

CODE

MsgBox(ex.message)



Run the code, if the catch triggers again this will give you more information on the error.
User is offlineProfile CardPM
+Quote Post

Core

RE: Try/Catch Problems

10 Jan, 2009 - 07:46 AM
Post #4

The .NET Dude
Group Icon

Joined: 8 Dec, 2008
Posts: 3,043



Thanked: 217 times
Dream Kudos: 900
Expert In: C#, VB.NET, WPF, .NET Framework

My Contributions
Well, if you look at your code, you have two verification statements If intCount >= 5 Then going one after another. As those are checking the same things, you should put them together.

What error are you getting when the exception raises?
User is online!Profile CardPM
+Quote Post

khulood Abdullah

RE: Try/Catch Problems

10 Jan, 2009 - 07:51 AM
Post #5

New D.I.C Head
*

Joined: 19 Dec, 2008
Posts: 5


My Contributions
QUOTE(Core @ 10 Jan, 2009 - 07:46 AM) *

Well, if you look at your code, you have two verification statements If intCount >= 5 Then going one after another. As those are checking the same things, you should put them together.

What error are you getting when the exception raises?



Well, the message "The info is already here" keeps on showing, although the inserted information does not match any thing that is already in the Database.

Thank You for cooperation.

User is offlineProfile CardPM
+Quote Post

AdamR

RE: Try/Catch Problems

10 Jan, 2009 - 09:11 AM
Post #6

D.I.C Head
**

Joined: 23 Sep, 2008
Posts: 144



Thanked: 7 times
My Contributions
Khulood, did you try using the following code in your Catch statement block,

CODE

msgbox(ex.message)


Then run the program, and see what the error is.
User is offlineProfile CardPM
+Quote Post

khulood Abdullah

RE: Try/Catch Problems

10 Jan, 2009 - 10:50 AM
Post #7

New D.I.C Head
*

Joined: 19 Dec, 2008
Posts: 5


My Contributions
QUOTE(AdamR @ 10 Jan, 2009 - 09:11 AM) *

Khulood, did you try using the following code in your Catch statement block,

CODE

msgbox(ex.message)


Then run the program, and see what the error is.


Yab I did, the returned message is "missing semicolon"
User is offlineProfile CardPM
+Quote Post

AdamR

RE: Try/Catch Problems

10 Jan, 2009 - 01:24 PM
Post #8

D.I.C Head
**

Joined: 23 Sep, 2008
Posts: 144



Thanked: 7 times
My Contributions
Ok, your next step would be to debug, stepping through your program, when you find the section that fails, you will discover where your semi colon needs to go smile.gif
User is offlineProfile CardPM
+Quote Post

khulood Abdullah

RE: Try/Catch Problems

10 Jan, 2009 - 02:10 PM
Post #9

New D.I.C Head
*

Joined: 19 Dec, 2008
Posts: 5


My Contributions
QUOTE(AdamR @ 10 Jan, 2009 - 01:24 PM) *

Ok, your next step would be to debug, stepping through your program, when you find the section that fails, you will discover where your semi colon needs to go smile.gif


Thanks a lot for your help, this is hint was a great help,
I am still looking for the error and from what it says I gess its in the sql commands.

rolleyes.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 07:03PM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month