Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents RadioButton3 As System.Windows.Forms.RadioButton
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.RadioButton1 = New System.Windows.Forms.RadioButton
Me.RadioButton2 = New System.Windows.Forms.RadioButton
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.RadioButton3 = New System.Windows.Forms.RadioButton
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(32, 200)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(128, 40)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'RadioButton1
'
Me.RadioButton1.Checked = True
Me.RadioButton1.Location = New System.Drawing.Point(24, 16)
Me.RadioButton1.Name = "RadioButton1"
Me.RadioButton1.Size = New System.Drawing.Size(216, 24)
Me.RadioButton1.TabIndex = 1
Me.RadioButton1.TabStop = True
Me.RadioButton1.Text = "DataSet"
'
'RadioButton2
'
Me.RadioButton2.Location = New System.Drawing.Point(24, 48)
Me.RadioButton2.Name = "RadioButton2"
Me.RadioButton2.Size = New System.Drawing.Size(216, 32)
Me.RadioButton2.TabIndex = 2
Me.RadioButton2.Text = "DataReader"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(24, 144)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(232, 20)
Me.TextBox1.TabIndex = 3
Me.TextBox1.Text = "TextBox1"
'
'RadioButton3
'
Me.RadioButton3.Location = New System.Drawing.Point(24, 96)
Me.RadioButton3.Name = "RadioButton3"
Me.RadioButton3.Size = New System.Drawing.Size(216, 24)
Me.RadioButton3.TabIndex = 4
Me.RadioButton3.Text = "Parameters.."
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.RadioButton3)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.RadioButton2)
Me.Controls.Add(Me.RadioButton1)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim tmStart As DateTime = Now()
Dim a, b, c As String
Dim DBLTM As Double = CType(Now.Minute.ToString & Now.Second.ToString & Now().Millisecond.ToString, Double)
If RadioButton1.Checked Then
Debug.Write("DataTable" & vbCrLf)
ElseIf RadioButton2.Checked Then
Debug.Write("DataReader" & vbCrLf)
Else
Debug.Write("Parameters")
End If
Debug.Write(DBLTM.ToString & " Start - " & vbCrLf)
Dim y As Integer
If IsNumeric(TextBox1.Text) Then
y = TextBox1.Text
Else
y = 15000
End If
For y = 0 To y
If RadioButton2.Checked = True Then
Dim dr As SqlClient.SqlDataReader = ABCDatareader()
dr.Read()
TextBox1.Text = dr.Item(0).ToString & ", " & dr(1).ToString & ", " & dr.Item(2).ToString
dr.Close()
dr = Nothing
GC.Collect()
ElseIf RadioButton1.Checked = True Then
Dim dt As DataTable = ABCDatatable()
TextBox1.Text = dt.Rows(0)(0).ToString & ", " & dt.Rows(0)(1).ToString & ", " & dt.Rows(0)(2).ToString
dt.Dispose()
dt = Nothing
GC.Collect()
Else
If ABC2Parameter(a, b, c) = True Then
TextBox1.Text = a & ", " & b & ", " & c
Else
MsgBox("problem")
Exit Sub
End If
End If
Next
Dim tmEnd As DateTime = Now()
Dim dblEnd As Double = CType(Now.Minute.ToString & Now.Second.ToString & Now().Millisecond.ToString, Double)
Debug.Write(dblEnd & " End Time" & vbCrLf)
Debug.Write(dblEnd - DBLTM & " time differenc in milliseconds " & vbCrLf & vbCrLf)
Me.Text = DateDiff(DateInterval.Second, tmStart, tmEnd)
MsgBox(Me.Text & "Seconds")
End Sub
#Region "database code built at lynchtek.com/sql.aspx"
Private Function ABCDatareader() As SqlClient.SqlDataReader
Dim con As New SqlClient.SqlConnection("server=(local);database=Northwind;trusted_connection=yes")
Dim cmd As New SqlClient.SqlCommand("abc", con)
Dim da As New SqlClient.SqlDataAdapter(cmd)
Dim dr As SqlClient.SqlDataReader
With cmd
.CommandType = CommandType.StoredProcedure
con.Open()
Try
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Catch ex As Exception
MsgBox(ex.Message)
'response.write ex.message
Return Nothing
Exit Function
Finally
cmd.Dispose()
End Try
End With
If dr Is Nothing Then
Return Nothing
Else
Return dr
End If
End Function
Private Function ABCDatatable() As DataTable
Dim con As New SqlClient.SqlConnection("server=(local);database=Northwind;trusted_connection=yes")
Dim cmd As New SqlClient.SqlCommand("abc", con)
Dim da As New SqlClient.SqlDataAdapter(cmd)
Dim dt As New DataTable
With cmd
.CommandType = CommandType.StoredProcedure
con.Open()
Try
da.Fill(dt)
Catch ex As Exception
Return Nothing
Exit Function
Finally
con.Close()
cmd.Dispose()
End Try
End With
If dt Is Nothing Then
Return Nothing
Else
Return dt
End If
End Function
Private Function ABC2Parameter(ByRef outPrmfirstname As String, ByRef outPrmlastname As String, ByRef outPrmtitle As String) As Boolean
Dim con As New SqlClient.SqlConnection("server=(local);database=Northwind;trusted_connection=yes")
Dim cmd As New SqlClient.SqlCommand("adb2", con)
Dim da As New SqlClient.SqlDataAdapter(cmd)
With cmd
.CommandType = CommandType.StoredProcedure
With .Parameters
.Add("@firstname", SqlDbType.VarChar, 3000).Direction = ParameterDirection.Output
.Add("@lastname", SqlDbType.VarChar, 3000).Direction = ParameterDirection.Output
.Add("@title", SqlDbType.VarChar, 3000).Direction = ParameterDirection.Output
End With
con.Open()
Try
cmd.ExecuteNonQuery() ' For a stored proc with no records...
outPrmfirstname = .Parameters("@firstname").Value.ToString
outPrmlastname = .Parameters("@lastname").Value.ToString
outPrmtitle = .Parameters("@title").Value.ToString
Catch ex As Exception
'msgbox ex.message
'response.write ex.message
Return False
Exit Function
Finally
con.Close()
cmd.Dispose()
End Try
End With
Return True
End Function
#End region
End Class