tekgod01 Posted October 31, 2006 Posted October 31, 2006 Sadly, I don't 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. I'm trying to get a listbox to populate with some SQL data. When I run it, it always stops at "myConnection.Open" with an error. Here's 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. Quote
Administrators PlausiblyDamp Posted October 31, 2006 Administrators Posted October 31, 2006 What is the error message contained within the exception? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
tekgod01 Posted October 31, 2006 Author Posted October 31, 2006 This is all I get: An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll Additional information: System error. Quote
TheWizardofInt Posted October 31, 2006 Posted October 31, 2006 Here is an example from some working code Try oConn = New SqlClient.SqlConnection("Server=" & cmbSQLServer.SelectedItem & ";Database=" & _ cmbDatabase.SelectedItem & ";uid=" & txtSQL.Text & ";pwd=" & txtSQLPass.Text & ";") oConn.Open() Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "An error has occurred") Exit Sub End Try sSQL = "Select Top 1 * FROM " & lstTables.SelectedItem Try cmd = New SqlClient.SqlCommand cmd.CommandText = sSQL cmd.Connection = oConn da = New SqlClient.SqlDataAdapter(cmd) da.Fill(dt) Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "An error has occurred!") oConn.Close() Exit Sub End Try Let me know if that doesn't send you on the right path Quote Read the Fovean Chronicles Because you just can't spend your whole day programming!
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.