473,382 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

VB.NET 2005 - exception question

I am working on a application that uses the MyApplication_UnhandledException
event to basically tell the user that I screwed up somewhere...see below

Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e
As Microsoft.VisualBasic.ApplicationServices.Unhandle dExceptionEventArgs)
Handles Me.UnhandledException
MsgBox(e.Exception.Message.ToString)
e.ExitApplication = False
End Sub

My test app that I was working on has 3 controls on it, A menu bar, textbox,
and datagrid. The app will take what I have in the textbox aka SQL Query,
then use the dataadapter to fill a dataset then bind it to the datagrid. Here
is where it gets weird, or at least I have no idea why this happens... First
here is my code...

I have a SQL class, which takes the query, and connection string and returns
a datatable

Imports System.Data
Imports System.Data.SqlClient

Public Class SQL

Private pResults As New DataTable
Private pQuery As String
Private pConnStr As String

Public ReadOnly Property Results() As DataTable
Get
Return pResults
End Get
End Property

Public Sub New(ByVal ConnStr As String, ByVal Query As String)
pConnStr = ConnStr
pQuery = Query
End Sub

Public Function ExecuteQuery() As DataTable
Dim DBConn As SqlConnection
Try
DBConn = New SqlConnection(pConnStr)
DBConn.Open()

Dim adp As New SqlDataAdapter(pQuery, DBConn)
adp.Fill(pResults)

Return pResults
Catch ex As Exception
Throw ex
Finally
DBConn.Close()
End Try
End Function
End Class

Also here is my main body of the testForm, the menubar has two items one
Parent (File) then a child node of Run with a shortcut key set to Ctrl+R

Private Const CONNECTION_STRING As String =
"uid=sa;password=SomePassword;initial catalog=SomeDatabase;data
source=wwwsql01,1433;connect timeout=15;persist security info=false;network
library=dbmssocn"

Private Sub RunToolStripMenuItem_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles RunToolStripMenuItem.Click
RunQuery()
End Sub

Private Sub RunQuery()
Dim qry As New SQL(Me.CONNECTION_STRING, TextBox1.Text)
qry.ExecuteQuery()

DataGridView1.DataSource = qry.Results
End Sub

Very simple... If I run it as is and an exception is thrown when I press
Ctrl+R while in the textbox, the unhandled exception handler will take over
and show me the exception but then place an "r" into the textbox. If I hit
Ctrl+R from the datagrid all is fine. If I use the mouse to click on Run all
is fine. So If I place a Try Catch around where I call RunQuery() and do not
use the MyApplication_UnhandledException but show a messagebox in the Try
Catch instead...The "r" as mentioned above does not show up at all. Would
anyone know the reasoning behind this? This app is nothing special just a
small test before I develop the larger version. All it does is run a SQL
query... Thanks in advance for anyhelp that you may be able to offer.
Nov 22 '05 #1
0 1459

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Steven | last post by:
I just downloaded the June 2005 release and I want to set up basic logging to log problems such as exceptions. I have created a category named Exceptions with the following: <category...
3
by: sacred_warrior | last post by:
After I saw Scott Guthrie's ASP.NET 2.0 with VS2005 seminar (which I think was great because I got to see all the cool features of VS 2005), I created a website using VS 2005 with option of File...
34
by: Bob | last post by:
Hi, The compiler gives Warning 96 Variable 'cmdSource' is used before it has been assigned a value. A null reference exception could result at runtime. Dim cmdSource as SQlClient.SQLDataReader...
2
by: raylopez99 | last post by:
I am trying to program a database from inside C++.NET via Visual Studio 2005 using the ADO.NET set of classes, but this I believe is a SQL Server 2005 Express permissions question under Windows XP...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.