Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with error message when trying to fill ds.

Status
Not open for further replies.

dollarbillg

Programmer
Dec 3, 2002
12
0
0
US
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 = &quot;cbo_Field&quot;
Me.cbo_Field.Size = New System.Drawing.Size(160, 21)
Me.cbo_Field.TabIndex = 0
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font(&quot;Microsoft Sans Serif&quot;, 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 = &quot;Label1&quot;
Me.Label1.Size = New System.Drawing.Size(48, 16)
Me.Label1.TabIndex = 1
Me.Label1.Text = &quot;Field&quot;
'
'Label2
'
Me.Label2.Font = New System.Drawing.Font(&quot;Microsoft Sans Serif&quot;, 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 = &quot;Label2&quot;
Me.Label2.Size = New System.Drawing.Size(72, 24)
Me.Label2.TabIndex = 2
Me.Label2.Text = &quot;Criteria&quot;
'
'cbo_Criteria
'
Me.cbo_Criteria.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
Me.cbo_Criteria.Items.AddRange(New Object() {&quot;IsNull&quot;, &quot;Null&quot;, &quot;Nothing&quot;, &quot;=&quot;, &quot;>&quot;, &quot;<&quot;, &quot;<=&quot;, &quot;>=&quot;})
Me.cbo_Criteria.Location = New System.Drawing.Point(96, 48)
Me.cbo_Criteria.Name = &quot;cbo_Criteria&quot;
Me.cbo_Criteria.Size = New System.Drawing.Size(160, 21)
Me.cbo_Criteria.TabIndex = 3
'
'Label3
'
Me.Label3.Font = New System.Drawing.Font(&quot;Microsoft Sans Serif&quot;, 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 = &quot;Label3&quot;
Me.Label3.Size = New System.Drawing.Size(56, 24)
Me.Label3.TabIndex = 4
Me.Label3.Text = &quot;Value&quot;
'
'txtValue
'
Me.txtValue.Location = New System.Drawing.Point(96, 88)
Me.txtValue.Name = &quot;txtValue&quot;
Me.txtValue.Size = New System.Drawing.Size(384, 20)
Me.txtValue.TabIndex = 5
Me.txtValue.Text = &quot;&quot;
'
'Label4
'
Me.Label4.Font = New System.Drawing.Font(&quot;Microsoft Sans Serif&quot;, 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 = &quot;Label4&quot;
Me.Label4.Size = New System.Drawing.Size(48, 24)
Me.Label4.TabIndex = 6
Me.Label4.Text = &quot;Sort&quot;
'
'cbo_Sort
'
Me.cbo_Sort.Location = New System.Drawing.Point(96, 128)
Me.cbo_Sort.Name = &quot;cbo_Sort&quot;
Me.cbo_Sort.Size = New System.Drawing.Size(160, 21)
Me.cbo_Sort.TabIndex = 7
'
'btnOK
'
Me.btnOK.Font = New System.Drawing.Font(&quot;Microsoft Sans Serif&quot;, 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 = &quot;btnOK&quot;
Me.btnOK.Size = New System.Drawing.Size(96, 24)
Me.btnOK.TabIndex = 8
Me.btnOK.Text = &quot;&OK&quot;
'
'btnClear
'
Me.btnClear.Font = New System.Drawing.Font(&quot;Microsoft Sans Serif&quot;, 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 = &quot;btnClear&quot;
Me.btnClear.Size = New System.Drawing.Size(96, 24)
Me.btnClear.TabIndex = 9
Me.btnClear.Text = &quot;Cl&ear&quot;
'
'btnCancel
'
Me.btnCancel.Font = New System.Drawing.Font(&quot;Microsoft Sans Serif&quot;, 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 = &quot;btnCancel&quot;
Me.btnCancel.Size = New System.Drawing.Size(104, 23)
Me.btnCancel.TabIndex = 10
Me.btnCancel.Text = &quot;&Cancel&quot;
'
'ckbSearch
'
Me.ckbSearch.Location = New System.Drawing.Point(8, 248)
Me.ckbSearch.Name = &quot;ckbSearch&quot;
Me.ckbSearch.Size = New System.Drawing.Size(128, 16)
Me.ckbSearch.TabIndex = 11
Me.ckbSearch.Text = &quot;Save This Search&quot;
'
'ckbResults
'
Me.ckbResults.Location = New System.Drawing.Point(144, 248)
Me.ckbResults.Name = &quot;ckbResults&quot;
Me.ckbResults.Size = New System.Drawing.Size(176, 16)
Me.ckbResults.TabIndex = 12
Me.ckbResults.Text = &quot;Show Results in a Select List&quot;
'
'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 = &quot;frmSearch&quot;
Me.Text = &quot; CSMP Search&quot;
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 = _
&quot;SELECT VALVE_ID, VALVELABEL &quot; & _
&quot;FROM VLI&quot;

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
&quot;**********************************************************

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 = &quot;Value_ID&quot;
.DisplayMember = &quot;VALVELABEL&quot;
End With


End Sub

End Class
Thanks
 
Sorry I did not mean to copy the form code. The application breaks at sda.fill(dsValve)
 
Check out the sqlerrorcollection to get a more detailed description.

Example:

Try
sda.Fill(dsValve)
Catch e As SqlException
Dim myErrors As SqlErrorCollection = e.Errors
Dim i As Integer
For i = 0 To myErrors.Errors.Count -1
Debug.WriteLine(&quot;Error #&quot; & myErrors(i).Number & &quot;: &quot; & myErrors(i).Message)
'Print whatever info you want from the error
Next i
End Try

Basically catch the SQL Server exception and you can look at the specific errors returned from it.
 
No that not it either. All I am trying to do is loop thru a dataset and add the records to the combo box. If you have code I could look at just to get a view of the correct procedure that would be cool. Everything I have tried to date has not functioned correctly. I've tried the tutorials. And I only get one value member instead of all of the values.

Dollarbillg
 
Try something like this:

With cbo_Field
.DataSource = dsValve.Tables(0)
.ValueMember = dsValve.Tables(0).columns(&quot;Value_ID&quot;)
.DisplayMember = &quot;VALVELABEL&quot;
End With
 
Sorry, that was the incorrect syntax. Try this:

ComboBox1.DataBindings.Add(&quot;text&quot;, ds.Tables(0), &quot;value_id&quot;)
ComboBox1.DisplayMember = &quot;value_id&quot;


O.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top