Sadly, I dont get to mess with Visual Basic very much and so my brain likes to rust. So when I have to come back to it about once a year, I have to relearn everything. Yay.
Im trying to get a listbox to populate with some SQL data. When I run it, it always stops at "myConnection.Open" with an error. Heres what I got so far. Am I missing something?
Public Class fmMain
Inherits System.Windows.Forms.Form
Dim myConnection As SqlConnection = New SqlConnection("server=home;database=dbRawMaterials")
Dim myDataAdapter As New SqlDataAdapter
Dim myDataSet = New DataSet
---
Private Sub fmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myDataAdapter.SelectCommand = New SqlCommand
myDataAdapter.SelectCommand.Connection = myConnection
myDataAdapter.SelectCommand.CommandText = "SELECT PartNumber FROM tblRawMaterials"
myDataAdapter.SelectCommand.CommandType = CommandType.Text
myConnection.Open()
myDataAdapter.SelectCommand.ExecuteNonQuery()
myDataAdapter.Fill(myDataSet, "PartNumber")
myConnection.Close()
lstParts.DataSource = myDataSet
End Sub
---
Any help would be appreciated. Thank you.
Im trying to get a listbox to populate with some SQL data. When I run it, it always stops at "myConnection.Open" with an error. Heres what I got so far. Am I missing something?
Public Class fmMain
Inherits System.Windows.Forms.Form
Dim myConnection As SqlConnection = New SqlConnection("server=home;database=dbRawMaterials")
Dim myDataAdapter As New SqlDataAdapter
Dim myDataSet = New DataSet
---
Private Sub fmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myDataAdapter.SelectCommand = New SqlCommand
myDataAdapter.SelectCommand.Connection = myConnection
myDataAdapter.SelectCommand.CommandText = "SELECT PartNumber FROM tblRawMaterials"
myDataAdapter.SelectCommand.CommandType = CommandType.Text
myConnection.Open()
myDataAdapter.SelectCommand.ExecuteNonQuery()
myDataAdapter.Fill(myDataSet, "PartNumber")
myConnection.Close()
lstParts.DataSource = myDataSet
End Sub
---
Any help would be appreciated. Thank you.