Private Sub butRunSelectAll_Click()
'Declare variables'
Dim objConn As ADODB.Connection
Dim objCmd As ADODB.Command
Dim objRecordset As ADODB.Recordset
Set objConn = New ADODB.Connection
Set objCmd = New ADODB.Command
Set objRecordset = New ADODB.Recordset
'Open Connection'
objConn.ConnectionString = "Provider=SQLOLEDB;Data Source=localhost\POC_QA;Initial Catalog=poc;User ID=user;Password=secretpass;"
objConn.Open
'Set and Excecute SQL Command'
Set objCmd.ActiveConnection = objConn
objCmd.CommandText = "select * from POC_DEV.dbo.Project_tb"
objCmd.CommandType = adCmdText
'Open Recordset'
Set objRecordset.Source = objCmd
objRecordset.Open
'Copy Data to Excel'
ActiveSheet.Range("A1").CopyFromRecordset objRecordset
End Sub
Private Sub butRunProc_Click()
'Declare variables'
Dim objConn As ADODB.Connection
Dim objCmd As ADODB.Command
Dim objRecordset As ADODB.Recordset
Set objConn = New ADODB.Connection
Set objCmd = New ADODB.Command
Set objRecordset = New ADODB.Recordset
'Open Connection'
objConn.ConnectionString = "Provider=SQLOLEDB;Data Source=localhost\POC_QA;Initial Catalog=CAS_DEV;User ID=user;Password=secretpass;"
objConn.Open
'Set and Excecute SQL Command'
Set objCmd.ActiveConnection = objConn
'We are going to use a stored procedure
objCmd.CommandType = adCmdStoredProc
'Add an Input parameter NOTE THE EMPTY ' ' !!!
objCmd.Parameters.Append objCmd.CreateParameter("@UserSessionId", adBigInt, adParamInput, , 12)
'Add an InOut parameter Note again no Size just an empty , ,
objCmd.Parameters.Append objCmd.CreateParameter("@Ret", adInteger, adParamInputOutput, , 1)
'Specify the name of the stored procedure
objCmd.CommandText = "procReport_Bug_SelectAll1"
'Action !!!
objCmd.Execute
'Open Recordset'
Set objRecordset.Source = objCmd
objRecordset.Open
'Copy Data to Excel'
ActiveSheet.Range("A1").CopyFromRecordset objRecordset
End Sub 'butRunProc_Click()
Private Sub TextBox1_Change()
End Sub
Private Sub UserForm_Click()
End Sub
Because every idiot could start writing spageti code like this after some 2 days of practice and start thinking that he / she is a real programmer hence the amount of data that could be transfered between the sql and the Excel !!!
No comments:
Post a Comment
- the first minus - Comments have to be moderated because of the spammers
- the second minus - I am very lazy at moderating comments ... hardly find time ...
- the third minus - Short links are no good for security ...
- The REAL PLUS : Any critic and positive feedback is better than none, so your comments will be published sooner or later !!!!