dollarbillg
Programmer
Please help with this code. All I am trying to do is fill a combo box with this sql statement.
Option Strict On
Imports System.Data.SqlClient
Imports System.Text
Public Class frmSearch
Inherits System.Windows.Forms.Form
Protected Const SQL_CONNECTION_STRING As String = _
"Server=localhost;" & _
"Database=VLI;" & _
"Integrated Security=SSPI"
Private sdr As SqlDataReader
Private strConn As String
#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 cbo_Field As System.Windows.Forms.ComboBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents cbo_Criteria As System.Windows.Forms.ComboBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents txtValue As System.Windows.Forms.TextBox
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents cbo_Sort As System.Windows.Forms.ComboBox
Friend WithEvents btnOK As System.Windows.Forms.Button
Friend WithEvents btnClear As System.Windows.Forms.Button
Friend WithEvents btnCancel As System.Windows.Forms.Button
Friend WithEvents ckbSearch As System.Windows.Forms.CheckBox
Friend WithEvents ckbResults As System.Windows.Forms.CheckBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.cbo_Field = New System.Windows.Forms.ComboBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.cbo_Criteria = New System.Windows.Forms.ComboBox()
Me.Label3 = New System.Windows.Forms.Label()
Me.txtValue = New System.Windows.Forms.TextBox()
Me.Label4 = New System.Windows.Forms.Label()
Me.cbo_Sort = New System.Windows.Forms.ComboBox()
Me.btnOK = New System.Windows.Forms.Button()
Me.btnClear = New System.Windows.Forms.Button()
Me.btnCancel = New System.Windows.Forms.Button()
Me.ckbSearch = New System.Windows.Forms.CheckBox()
Me.ckbResults = New System.Windows.Forms.CheckBox()
Me.SuspendLayout()
'
'cbo_Field
'
Me.cbo_Field.AllowDrop = True
Me.cbo_Field.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
Me.cbo_Field.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cbo_Field.Location = New System.Drawing.Point(96, 16)
Me.cbo_Field.Name = "cbo_Field"
Me.cbo_Field.Size = New System.Drawing.Size(160, 21)
Me.cbo_Field.TabIndex = 0
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(16, 16)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(48, 16)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Field"
'
'Label2
'
Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label2.Location = New System.Drawing.Point(16, 48)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(72, 24)
Me.Label2.TabIndex = 2
Me.Label2.Text = "Criteria"
'
'cbo_Criteria
'
Me.cbo_Criteria.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
Me.cbo_Criteria.Items.AddRange(New Object() {"IsNull", "Null", "Nothing", "=", ">", "<", "<=", ">="})
Me.cbo_Criteria.Location = New System.Drawing.Point(96, 48)
Me.cbo_Criteria.Name = "cbo_Criteria"
Me.cbo_Criteria.Size = New System.Drawing.Size(160, 21)
Me.cbo_Criteria.TabIndex = 3
'
'Label3
'
Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label3.Location = New System.Drawing.Point(16, 88)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(56, 24)
Me.Label3.TabIndex = 4
Me.Label3.Text = "Value"
'
'txtValue
'
Me.txtValue.Location = New System.Drawing.Point(96, 88)
Me.txtValue.Name = "txtValue"
Me.txtValue.Size = New System.Drawing.Size(384, 20)
Me.txtValue.TabIndex = 5
Me.txtValue.Text = ""
'
'Label4
'
Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label4.Location = New System.Drawing.Point(16, 128)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(48, 24)
Me.Label4.TabIndex = 6
Me.Label4.Text = "Sort"
'
'cbo_Sort
'
Me.cbo_Sort.Location = New System.Drawing.Point(96, 128)
Me.cbo_Sort.Name = "cbo_Sort"
Me.cbo_Sort.Size = New System.Drawing.Size(160, 21)
Me.cbo_Sort.TabIndex = 7
'
'btnOK
'
Me.btnOK.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnOK.Location = New System.Drawing.Point(336, 240)
Me.btnOK.Name = "btnOK"
Me.btnOK.Size = New System.Drawing.Size(96, 24)
Me.btnOK.TabIndex = 8
Me.btnOK.Text = "&OK"
'
'btnClear
'
Me.btnClear.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnClear.Location = New System.Drawing.Point(448, 240)
Me.btnClear.Name = "btnClear"
Me.btnClear.Size = New System.Drawing.Size(96, 24)
Me.btnClear.TabIndex = 9
Me.btnClear.Text = "Cl&ear"
'
'btnCancel
'
Me.btnCancel.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnCancel.Location = New System.Drawing.Point(560, 240)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(104, 23)
Me.btnCancel.TabIndex = 10
Me.btnCancel.Text = "&Cancel"
'
'ckbSearch
'
Me.ckbSearch.Location = New System.Drawing.Point(8, 248)
Me.ckbSearch.Name = "ckbSearch"
Me.ckbSearch.Size = New System.Drawing.Size(128, 16)
Me.ckbSearch.TabIndex = 11
Me.ckbSearch.Text = "Save This Search"
'
'ckbResults
'
Me.ckbResults.Location = New System.Drawing.Point(144, 248)
Me.ckbResults.Name = "ckbResults"
Me.ckbResults.Size = New System.Drawing.Size(176, 16)
Me.ckbResults.TabIndex = 12
Me.ckbResults.Text = "Show Results in a Select List"
'
'frmSearch
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(696, 277)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ckbResults, Me.ckbSearch, Me.btnCancel, Me.btnClear, Me.btnOK, Me.cbo_Sort, Me.Label4, Me.txtValue, Me.Label3, Me.cbo_Criteria, Me.Label2, Me.Label1, Me.cbo_Field})
Me.Name = "frmSearch"
Me.Text = " CSMP Search"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub frmSearch_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
strConn = SQL_CONNECTION_STRING
Dim strSQL As String = _
"SELECT VALVE_ID, VALVELABEL " & _
"FROM VLI"
Dim scnnVLI As New SqlConnection(strConn)
Dim scmd As New SqlCommand(strConn, scnnVLI)
'******************************************************
'BREAKS AT THE NEXT STATEMENT WITH THE FOLLOWING ERROR MSG
'Unhandled exception of Type.Data.SQLCLIENT.SQLEXCEPTION
'ocurred in system.data.dll
"**********************************************************
Dim dsValve As DataSet
Dim sda As New SqlDataAdapter(scmd)
'Dim arlValveLabel As New ArrayList()
dsValve = New DataSet()
sda.Fill(dsValve)
With cbo_Field
.DataSource = dsValve.Tables(0)
.ValueMember = "Value_ID"
.DisplayMember = "VALVELABEL"
End With
End Sub
End Class
Thanks
Option Strict On
Imports System.Data.SqlClient
Imports System.Text
Public Class frmSearch
Inherits System.Windows.Forms.Form
Protected Const SQL_CONNECTION_STRING As String = _
"Server=localhost;" & _
"Database=VLI;" & _
"Integrated Security=SSPI"
Private sdr As SqlDataReader
Private strConn As String
#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 cbo_Field As System.Windows.Forms.ComboBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents cbo_Criteria As System.Windows.Forms.ComboBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents txtValue As System.Windows.Forms.TextBox
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents cbo_Sort As System.Windows.Forms.ComboBox
Friend WithEvents btnOK As System.Windows.Forms.Button
Friend WithEvents btnClear As System.Windows.Forms.Button
Friend WithEvents btnCancel As System.Windows.Forms.Button
Friend WithEvents ckbSearch As System.Windows.Forms.CheckBox
Friend WithEvents ckbResults As System.Windows.Forms.CheckBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.cbo_Field = New System.Windows.Forms.ComboBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.cbo_Criteria = New System.Windows.Forms.ComboBox()
Me.Label3 = New System.Windows.Forms.Label()
Me.txtValue = New System.Windows.Forms.TextBox()
Me.Label4 = New System.Windows.Forms.Label()
Me.cbo_Sort = New System.Windows.Forms.ComboBox()
Me.btnOK = New System.Windows.Forms.Button()
Me.btnClear = New System.Windows.Forms.Button()
Me.btnCancel = New System.Windows.Forms.Button()
Me.ckbSearch = New System.Windows.Forms.CheckBox()
Me.ckbResults = New System.Windows.Forms.CheckBox()
Me.SuspendLayout()
'
'cbo_Field
'
Me.cbo_Field.AllowDrop = True
Me.cbo_Field.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
Me.cbo_Field.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.cbo_Field.Location = New System.Drawing.Point(96, 16)
Me.cbo_Field.Name = "cbo_Field"
Me.cbo_Field.Size = New System.Drawing.Size(160, 21)
Me.cbo_Field.TabIndex = 0
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.Location = New System.Drawing.Point(16, 16)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(48, 16)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Field"
'
'Label2
'
Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label2.Location = New System.Drawing.Point(16, 48)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(72, 24)
Me.Label2.TabIndex = 2
Me.Label2.Text = "Criteria"
'
'cbo_Criteria
'
Me.cbo_Criteria.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
Me.cbo_Criteria.Items.AddRange(New Object() {"IsNull", "Null", "Nothing", "=", ">", "<", "<=", ">="})
Me.cbo_Criteria.Location = New System.Drawing.Point(96, 48)
Me.cbo_Criteria.Name = "cbo_Criteria"
Me.cbo_Criteria.Size = New System.Drawing.Size(160, 21)
Me.cbo_Criteria.TabIndex = 3
'
'Label3
'
Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label3.Location = New System.Drawing.Point(16, 88)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(56, 24)
Me.Label3.TabIndex = 4
Me.Label3.Text = "Value"
'
'txtValue
'
Me.txtValue.Location = New System.Drawing.Point(96, 88)
Me.txtValue.Name = "txtValue"
Me.txtValue.Size = New System.Drawing.Size(384, 20)
Me.txtValue.TabIndex = 5
Me.txtValue.Text = ""
'
'Label4
'
Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label4.Location = New System.Drawing.Point(16, 128)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(48, 24)
Me.Label4.TabIndex = 6
Me.Label4.Text = "Sort"
'
'cbo_Sort
'
Me.cbo_Sort.Location = New System.Drawing.Point(96, 128)
Me.cbo_Sort.Name = "cbo_Sort"
Me.cbo_Sort.Size = New System.Drawing.Size(160, 21)
Me.cbo_Sort.TabIndex = 7
'
'btnOK
'
Me.btnOK.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnOK.Location = New System.Drawing.Point(336, 240)
Me.btnOK.Name = "btnOK"
Me.btnOK.Size = New System.Drawing.Size(96, 24)
Me.btnOK.TabIndex = 8
Me.btnOK.Text = "&OK"
'
'btnClear
'
Me.btnClear.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnClear.Location = New System.Drawing.Point(448, 240)
Me.btnClear.Name = "btnClear"
Me.btnClear.Size = New System.Drawing.Size(96, 24)
Me.btnClear.TabIndex = 9
Me.btnClear.Text = "Cl&ear"
'
'btnCancel
'
Me.btnCancel.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnCancel.Location = New System.Drawing.Point(560, 240)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.Size = New System.Drawing.Size(104, 23)
Me.btnCancel.TabIndex = 10
Me.btnCancel.Text = "&Cancel"
'
'ckbSearch
'
Me.ckbSearch.Location = New System.Drawing.Point(8, 248)
Me.ckbSearch.Name = "ckbSearch"
Me.ckbSearch.Size = New System.Drawing.Size(128, 16)
Me.ckbSearch.TabIndex = 11
Me.ckbSearch.Text = "Save This Search"
'
'ckbResults
'
Me.ckbResults.Location = New System.Drawing.Point(144, 248)
Me.ckbResults.Name = "ckbResults"
Me.ckbResults.Size = New System.Drawing.Size(176, 16)
Me.ckbResults.TabIndex = 12
Me.ckbResults.Text = "Show Results in a Select List"
'
'frmSearch
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(696, 277)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ckbResults, Me.ckbSearch, Me.btnCancel, Me.btnClear, Me.btnOK, Me.cbo_Sort, Me.Label4, Me.txtValue, Me.Label3, Me.cbo_Criteria, Me.Label2, Me.Label1, Me.cbo_Field})
Me.Name = "frmSearch"
Me.Text = " CSMP Search"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub frmSearch_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
strConn = SQL_CONNECTION_STRING
Dim strSQL As String = _
"SELECT VALVE_ID, VALVELABEL " & _
"FROM VLI"
Dim scnnVLI As New SqlConnection(strConn)
Dim scmd As New SqlCommand(strConn, scnnVLI)
'******************************************************
'BREAKS AT THE NEXT STATEMENT WITH THE FOLLOWING ERROR MSG
'Unhandled exception of Type.Data.SQLCLIENT.SQLEXCEPTION
'ocurred in system.data.dll
"**********************************************************
Dim dsValve As DataSet
Dim sda As New SqlDataAdapter(scmd)
'Dim arlValveLabel As New ArrayList()
dsValve = New DataSet()
sda.Fill(dsValve)
With cbo_Field
.DataSource = dsValve.Tables(0)
.ValueMember = "Value_ID"
.DisplayMember = "VALVELABEL"
End With
End Sub
End Class
Thanks