newby problem

C

campbellbrian2001

Thanks all in advance. A couple of questions: I was trying to set up a
form with a datagrid to display . I have a successful attachment to an
Access Database (Northwind).
The code below failed. I had copied it as a lab exercise

(I get the following error message: "An unhandled exception of type
'System.Data.SqlClient.SqlException' occurred in system.data.dll
Additional information: System error.")

Imports System.Data
Imports System.Data.SqlClient

Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim cmd As SqlCommand = SqlConnection1.CreateCommand
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "procFranceCustomers"
Dim da As SqlDataAdapter = New SqlDataAdapter
da.SelectCommand = cmd
Dim ds As DataSet = New DataSet
da.Fill(ds, "Customers")
dgresults.DataSource = ds
dgresults.DataMember = "Customers"
End Sub
End Class

Also why does the IDE prevent me from placing Parenthecals "()" ?

Line should read Dim ds As DataSet = New DataSet()
Line should read Dim da As SqlDataAdapter = New SqlDataAdapter()
 
E

Earl

Use Try-Catch in your data acess code.

The reason your code fails is that you are trying to connect to Access
using SQL stored procedure, client, adapater, etc. None of that will work.

Set up with OleDB and use command text for your query (Access has no
sprocs).

You need a good book on ADO.Net.
 
E

Earl

I've heard that rumored, but not dug into it. What version and is this a
supported feature?
 
E

Earl

Well, the 3rd link would've been enough and kept me from wading through all
the basic trivia of the first 2, but I do see that Access 2000 has
"procedures" used similar to an SQL stored procedure. Not that I use Access
much anymore, but good info to know.

But before we lose the OP entirely, the gist of the answer is still correct
in that he was trying to connect to Access
using SQL stored procedure, client, adapater, etc. -- which will not work
(and while it's possible, I further doubt he had a "procedure" built in
Access that he was calling).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top