Click here to Skip to main content
16,005,038 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: datagrid header text Pin
abhinish20-Jan-06 18:30
abhinish20-Jan-06 18:30 
AnswerRe: datagrid header text Pin
Dave Kreskowiak21-Jan-06 4:26
mveDave Kreskowiak21-Jan-06 4:26 
AnswerRe: datagrid header text Pin
Mekong River21-Jan-06 4:48
Mekong River21-Jan-06 4:48 
QuestionSearch button Pin
shakizil20-Jan-06 7:07
shakizil20-Jan-06 7:07 
AnswerRe: Search button Pin
Mike K. Clark20-Jan-06 9:50
Mike K. Clark20-Jan-06 9:50 
GeneralRe: Search button Pin
shakizil20-Jan-06 10:48
shakizil20-Jan-06 10:48 
AnswerRe: Search button Pin
Mike K. Clark20-Jan-06 13:42
Mike K. Clark20-Jan-06 13:42 
GeneralRe: Search button Pin
Icharus20-Jan-06 15:20
Icharus20-Jan-06 15:20 
Try the following with your function:

Public Function GetAllChangeControl() As String
Dim con As OleDbConnection
Dim cmd As OleDbCommand = New OleDbCommand

con = New OleDbConnection(connectionstring)
cmd.Connection = con

cmd.CommandText = "EXECUTE GetAllChangeControl"
con.Open()

'---------------------------------------------
' Here is the change
Dim retVal As Object
Try
retVal = cmd.ExecuteScalar()
If Not(IsNothing(retVal)) Then
Return Cstr(retVal)
Else
Return String.Empty
End If
Catch ex As OledbException
Throw ex
Finally
con.Close()
If Not con Is Nothing Then con.Dispose
If Not cmd Is Nothing Then cmd.Dispose
End Try
'------------------------------------------

End Function

Let me explain, it is possible that your "cmd.ExecuteScalar" is not returning anything and you are not checking for that, so what I've done here is do a simple check and return the appropriate value. I have also enclosed the procedure in a Try statement to capture the Exception, and make sure that even if an Exception is thrown, the connection is closed and you realease your resources.

I hope this helps.

QuestionDateTimepicker Pin
shakizil20-Jan-06 5:44
shakizil20-Jan-06 5:44 
AnswerRe: DateTimepicker Pin
Dave Kreskowiak20-Jan-06 6:15
mveDave Kreskowiak20-Jan-06 6:15 
GeneralRe: DateTimepicker Pin
shakizil20-Jan-06 6:23
shakizil20-Jan-06 6:23 
GeneralRe: DateTimepicker Pin
Dave Kreskowiak20-Jan-06 6:30
mveDave Kreskowiak20-Jan-06 6:30 
GeneralRe: DateTimepicker Pin
Mekong River21-Jan-06 4:53
Mekong River21-Jan-06 4:53 
GeneralRe: DateTimepicker Pin
Dave Kreskowiak21-Jan-06 8:36
mveDave Kreskowiak21-Jan-06 8:36 
AnswerRe: DateTimepicker Pin
Mike K. Clark20-Jan-06 6:26
Mike K. Clark20-Jan-06 6:26 
GeneralRe: DateTimepicker Pin
shakizil20-Jan-06 6:36
shakizil20-Jan-06 6:36 
Questionefficient control redrawing Pin
JW73820-Jan-06 4:46
JW73820-Jan-06 4:46 
AnswerRe: efficient control redrawing Pin
Dave Kreskowiak20-Jan-06 6:05
mveDave Kreskowiak20-Jan-06 6:05 
GeneralRe: efficient control redrawing Pin
JW73820-Jan-06 16:42
JW73820-Jan-06 16:42 
GeneralRe: efficient control redrawing Pin
Dave Kreskowiak20-Jan-06 18:14
mveDave Kreskowiak20-Jan-06 18:14 
GeneralRe: efficient control redrawing Pin
JW73820-Jan-06 21:15
JW73820-Jan-06 21:15 
QuestionProgram works in debug but exe has errors Pin
jonathan1520-Jan-06 4:16
jonathan1520-Jan-06 4:16 
AnswerRe: Program works in debug but exe has errors Pin
Dave Kreskowiak20-Jan-06 4:23
mveDave Kreskowiak20-Jan-06 4:23 
GeneralRe: Program works in debug but exe has errors Pin
jonathan1520-Jan-06 4:35
jonathan1520-Jan-06 4:35 
GeneralRe: Program works in debug but exe has errors Pin
Dave Kreskowiak20-Jan-06 5:35
mveDave Kreskowiak20-Jan-06 5:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.