Trying to learn C# and Web Service

Posted on 2009-02-09
Last Modified: 2012-05-06
Okay...I'm trying to learn something new and having problems.
I want to write a webservice and use an aspx file to read it.  All files will be located on my 'work' web server,  My database is in MS Access 2005.  I have written my asmx file and compiled it okay with wsdl to get my cs file, and used csc to convert that to DLL.  So, I am able to call my asmx file and get the method listing.


I am trying to read the Access db using an OLEdb, and NOT Sql C# syntax.  Is this correct?

I think that using a datagrid might be a problem.

Any ideas? explanation.....PPLLEEAASSEE (whiny voice)


my ASMX file



<%@ WebService Class="BeerServiceDB" Language="C#" %>

using System;

using System.Web.Services;

using System.Data;

using System.Data.OleDb;


[WebService( Namespace="" )]


public class BeerServiceDB : WebService


    [WebMethod(Description="This method returns the 'Beer' catalog.")]

        public DataSet processQuoteRequest() {

            string strSelect = "Select ProductName, ProductDescription, UnitPrice, filepath From Beers;";

            OleDbConnection myConnection = new OleDbConnection "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=../Database/KochBeer.mdb");

           OleDbCommand myCommand = new OleDbCommand(strSelect, myConnection);

           OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myCommand);

           DataSet myDataSet = new DataSet();

           myDataAdapter.Fill(myDataSet, "Beers");

           return myDataSet;





Attempted ASPX file to read and send back a DataSet with the data.


<%@ Page Language="C#" %>

<script language="C#" runat=server>


void Page_Load(Object sender , EventArgs e) {

     BeerServiceDB objBeers = new BeerServiceDB();

     dgrdBeers.DataSource = objBeers.processQuoteRequest();









<h2>Available Beers:</h2>

<asp:DataGrid  ID="dgrdBeers"  Runat="Server"/>




Open in new window

Question by:Bob Bender
    LVL 11

    Accepted Solution

    <<<I am trying to read the Access db using an OLEdb, and NOT Sql C# syntax.  Is this correct?
    Yes this is correct
    I guess in your code you forgot to open the connection, so your code
    OleDbConnection myConnection = new OleDbConnection "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=../Database/KochBeer.mdb");
               OleDbCommand myCommand = new OleDbCommand(strSelect, myConnection);
    should be like this
     OleDbConnection myConnection = new OleDbConnection "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=../Database/KochBeer.mdb");
    OleDbCommand myCommand = new OleDbCommand(strSelect, myConnection);

    Also don't forgot to close the connection once data is fetched
    LVL 11

    Expert Comment

    sorry, i think i missed some code to read...
    I beleive adding one attribute autogeneratecolumns=true will work for you in
    <asp:DataGrid  ID="dgrdBeers"  Runat="Server"/>
    LVL 5

    Author Closing Comment

    by:Bob Bender
    A couple of other lines had to change, but it now works!  Thanx!

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API ( has made its way into the popular lexicon of the English language.  A few years ago, …
    The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now