Hey guys, long time no see. I decided to play around with SQL using VB.Net with ADO.Net, and for some reason I just can't seem to connect to the database file. I used Tools > Connect to Database, and linked the file with that, which is an accdb file from Access. Didn't change anything really afterwards. And then I ran this code:
As a result, I get an unhandled exception. I even tried using an mdb file, and it still fails. Even tried adding "Initial Catalog=Database1;Integrated Security=True" for the myConn connection, and nothing worked. Anyone got any bright ideas? Thanks in advance. :bigyello:
vb.net Code:
Option Explicit On Option Strict On Imports System.Data.SqlClient Public Class Form1 Private myConn As SqlConnection Private myCmd As SqlCommand Private myReader As SqlDataReader Private results As String Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load myConn = New SqlConnection("Data Source = Database1") 'Open the connection. myConn.Open() End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 'Create a Command object. myCmd = myConn.CreateCommand myCmd.CommandText = "SELECT * FROM Table1 WHERE ID = " & TextBox1.Text myReader = myCmd.ExecuteReader() results = results & myReader.GetString(0) & vbTab & myReader.GetString(1) Label1.Text = results End Sub End Class
As a result, I get an unhandled exception. I even tried using an mdb file, and it still fails. Even tried adding "Initial Catalog=Database1;Integrated Security=True" for the myConn connection, and nothing worked. Anyone got any bright ideas? Thanks in advance. :bigyello: