Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.
~~~~~~Connection String~~~~~~~ Private Const ConnectionString As String = "User ID=myuser;Password=password;Data Source=SERVER\SQLEXPRESS;Database=MyDB;" ~~~~~~~~This is how i call the below procs (the sample is for the datareader)~~~~~~~~~ dr = DataHandlerSqlClient.GetDataReader(strSQL) ~~~~~~My 3 Connection Procs~~~~~~~ ~~~~~~These are the only PROC's i have to execute SQL's(INSERT,UPDATE,DELETE,SELECT)~~~~~~~ Public Shared Function ExecuteSQL(ByVal SQLStatement As String) As Integer Dim cmd As SqlCommand Dim intRows As Integer cmd = Nothing Try cmd = New SqlCommand() With cmd ' Create a Connection object .Connection = New SqlConnection(ConnectionString) ' Fill in command text, set type .CommandText = SQLStatement .CommandType = CommandType.Text ' Open the Connection .Connection.Open() ' Execute SQL intRows = .ExecuteNonQuery() End With Catch Throw Finally ' Close the connection With cmd.Connection If .State = ConnectionState.Open Then .Close() End If End With End Try Return intRows End Function Public Shared Function GetDataReader(ByVal SQLStatement As String) As SqlDataReader Dim dr As SqlDataReader Dim cmd As New SqlCommand() With cmd .Connection = New SqlConnection(ConnectionString) .Connection.Open() .CommandText = SQLStatement dr = .ExecuteReader(CommandBehavior.CloseConnection) End With Return dr End Function Public Shared Function GetDataSet(ByVal SQL As String) As DataSet Dim da As SqlDataAdapter Dim ds As DataSet Try ' Create New DataAdapter da = New SqlDataAdapter(SQL, ConnectionString) ' Fill DataSet from DataAdapter ds = New DataSet() da.Fill(ds) Catch Throw End Try Return ds End Function
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.