Click here to Skip to main content
16,004,944 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: conversion from excel to pdf Pin
Member 199825024-Jun-05 2:56
Member 199825024-Jun-05 2:56 
GeneralRe: conversion from excel to pdf Pin
Dave Kreskowiak24-Jun-05 3:51
mveDave Kreskowiak24-Jun-05 3:51 
Generalweb service error Pin
monageasmear24-Jun-05 0:04
monageasmear24-Jun-05 0:04 
GeneralRe: web service error Pin
Dave Kreskowiak24-Jun-05 1:46
mveDave Kreskowiak24-Jun-05 1:46 
GeneralRe: web service error Pin
monageasmear24-Jun-05 3:42
monageasmear24-Jun-05 3:42 
QuestionHOW TO CHANGE THE COLOUR OF MSGBOX/INPUTBOX,ETC FROM ITS DEFAULT COLOUR Pin
LAYEEQ AHMED KHAN23-Jun-05 8:15
LAYEEQ AHMED KHAN23-Jun-05 8:15 
AnswerRe: HOW TO CHANGE THE COLOUR OF MSGBOX/INPUTBOX,ETC FROM ITS DEFAULT COLOUR Pin
Dave Kreskowiak23-Jun-05 9:11
mveDave Kreskowiak23-Jun-05 9:11 
GeneralGood programming - memory allocation Pin
Sled Dog23-Jun-05 4:01
Sled Dog23-Jun-05 4:01 
Coding Dogs,

I would like to know that I am programming correctly & responsibly. Would you say that the new version of this function is correct as it concerns allocating and deallocating new objects? Or do I even have to bother with this? a.k.a. Can I just rely on the .NET environment to handle memory management once a DIM goes out of scope?

I am a C# programmer and I feel like the NEW VERSION is correct, but I am not sure. Also, I did not like variables declared on the fly.

Thank you in advance for any opinions.

William-SD Confused | :confused:

'NEW VERSION'
Public Shared Function GetData(ByRef SQL As String) As System.Data.DataSet
Dim cn As System.Data.SqlClient.SqlConnection
Dim adp As System.Data.SqlClient.SqlDataAdapter
Dim ds As System.Data.DataSet = New System.Data.DataSet

Try
cn = New System.Data.SqlClient.SqlConnection(ConnectionString)

If Not (cn.State = ConnectionState.Open) Then
Throw New System.Exception("Database connection failed")
End If

adp = New System.Data.SqlClient.SqlDataAdapter(SQL, cn)

If (Len(SQL) > 0) Then
cn.Open()
adp.Fill(ds)
GetData = ds
Else
ds.Dispose()
ds = Nothing
GetData = New System.Data.DataSet 'return nothing in an empty dataset
End If

Catch
ds.Dispose()
ds = Nothing
GetData = New System.Data.DataSet 'return nothing in an empty dataset

Finally
cn.Close()
adp.Dispose()
cn.Dispose()
adp = Nothing
cn = Nothing
End Try

End Function

'OLD VERSION'
Public Function GetData(ByRef SQL As String, ByRef ConnectionString As String) As System.Data.DataSet
Dim ds As System.Data.DataSet = New System.Data.DataSet

If (Len(SQL) > 0) Then
Dim cn As System.Data.SqlClient.SqlConnection = Connect(ConnectionString)
Try
Dim cmd As SqlClient.SqlCommand = cn.CreateCommand()
cmd.CommandText = SQL
cmd.CommandType = CommandType.Text
Dim adp As System.Data.SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(cmd)
adp.Fill(ds)
Finally
cn.Close()
End Try
End If

GetData = ds
End Function

GeneralRe: Good programming - memory allocation Pin
T-Smooth23-Jun-05 6:42
T-Smooth23-Jun-05 6:42 
GeneralRe: Good programming - memory allocation Pin
StylezHouse23-Jun-05 9:13
StylezHouse23-Jun-05 9:13 
GeneralRe: Good programming - memory allocation Pin
Anonymous23-Jun-05 21:08
Anonymous23-Jun-05 21:08 
GeneralRe: Good programming - memory allocation Pin
StylezHouse23-Jun-05 9:18
StylezHouse23-Jun-05 9:18 
GeneralRe: Good programming - memory allocation Pin
T-Smooth24-Jun-05 1:13
T-Smooth24-Jun-05 1:13 
GeneralRe: Good programming - memory allocation [EDITED] Pin
Dave Kreskowiak24-Jun-05 1:31
mveDave Kreskowiak24-Jun-05 1:31 
GeneralRe: Good programming - memory allocation [EDITED] Pin
T-Smooth24-Jun-05 1:47
T-Smooth24-Jun-05 1:47 
GeneralRe: Good programming - memory allocation [EDITED] Pin
StylezHouse24-Jun-05 2:44
StylezHouse24-Jun-05 2:44 
Generalformat problem Pin
Member 203133523-Jun-05 3:56
Member 203133523-Jun-05 3:56 
GeneralRe: format problem Pin
Dave Kreskowiak23-Jun-05 4:54
mveDave Kreskowiak23-Jun-05 4:54 
GeneralRe: format problem Pin
Member 203133523-Jun-05 18:49
Member 203133523-Jun-05 18:49 
GeneralRe: format problem Pin
Dave Kreskowiak24-Jun-05 1:29
mveDave Kreskowiak24-Jun-05 1:29 
GeneralDataGrid Column Formating Pin
directred23-Jun-05 1:45
directred23-Jun-05 1:45 
GeneralRe: DataGrid Column Formating Pin
Het210923-Jun-05 18:52
Het210923-Jun-05 18:52 
GeneralRe: DataGrid Column Formating Pin
directred23-Jun-05 23:37
directred23-Jun-05 23:37 
GeneralRe: DataGrid Column Formating Pin
Het210923-Jun-05 23:56
Het210923-Jun-05 23:56 
GeneralRe: DataGrid Column Formating Pin
directred27-Jun-05 0:15
directred27-Jun-05 0:15 

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.