2 Replies - 592 Views - Last Post: 25 March 2012 - 07:36 AM Rate Topic: -----

#1 ScottinTexas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 45
  • Joined: 13-March 12

Fill and read the values of a dataset

Posted 25 March 2012 - 06:15 AM

I have read several articles on how to use the dataset, but I am missing something somewhere. I have a class that is to be used to store several parameters for use throughout the program. When I instantiate a new class I want it to access my Access database and retrieve the various values. Then when I need one I can simply execute a call to the class with myClass.RSID.ToString() or whatever. I'll cross that bridge when I get to it. BTW, some of the values are longs (Int32) but I don't see a ToLong() method anywhere.

The class
    public class clsRunsheet
    {
        private Int32 tractID;
        private Int32 stateID;
        private Int32 prosID;
        private Int32 rsID;
        private Int32 surID;
        private float tractAcres;
        private string tractDesc;
        private string tractName;
        private string prosName;
        private string stName;
        private string surName;

        public Int32 TractID
        {
            get {return tractID;}
        }
        public Int32 StatID
        {
            get{return stateID;}
        }
        public Int32 ProspectID
        {
            get{return prosID;}
        }
        public Int32 RunsheetID
        {
            get {return rsID;}
        }
        public Int32 SurveyID
        {
            get{return surID;}
        }
        public float Acreage
        {
            get{return tractAcres;}
        }
        public string Description
        {
            get {return tractDesc;}
        }
        public string TractName
        {
            get{return tractName;}
        }
        public string Prospect
        {
            get{return prosName;}
        }
        public string State
        {
            get{return stName;}
        }
        public string Survey
        {
            get{return surName;}
        }

        public clsRunsheet(string tractNo)
        {
            string strAccessCon=@"Provider=Microsoft.Jet.OLEDB.4.0;" +
                @"Data Source=C:\Users\Scot\Documents\Landman\NewLandman.accdb";
            DataSet thisDataSet=new DataSet();
            OleDbConnection thisCon=new OleDbConnection(strAccessCon);
            OleDbDataAdapter daTracts =new OleDbDataAdapter();
            OleDbCommand selectCmd=new OleDbCommand("Select TractName, TractID, SurveyID, TractDescription WHERE TractID=@tractNo", thisCon);
            daTracts.SelectCommand=selectCmd;
            daTracts.Fill(thisDataSet,"tblTracts");
            tractName=daTracts.ToString();

        }
    }



The first thing that happens when I try to run this code is that I get an "Unrecognized database format" error plus a whole bunch of other information.

The final line in the code is expected to retrieve the name of the Tract. I have read several articles and other information that people have pointed me to and I have found, but none seem to be doing the same sort of thing. Since this is a class without a form I can't just drag the dataadapters etc onto it to let the wizard handle it.
How can I do this? And what about when I want a long instead of a string. Do I have to create a ToLong() method?

Is This A Good Question/Topic? 0
  • +

Replies To: Fill and read the values of a dataset

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6110
  • View blog
  • Posts: 23,670
  • Joined: 23-August 08

Re: Fill and read the values of a dataset

Posted 25 March 2012 - 06:26 AM

Not well-versed in Access, but I Googled "ado accdb" -- looking for info on your error -- and this was the first link.

You also don't want to be using ToString() on a DataAdapter. That's not going to give you anything of use.

Sounds like you really need to read up on Using ADO.NET. This might be helpful as well. You need to understand how all the moving parts fit together, or you're going to struggle needlessly.
Was This Post Helpful? 1
  • +
  • -

#3 ScottinTexas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 45
  • Joined: 13-March 12

Re: Fill and read the values of a dataset

Posted 25 March 2012 - 07:36 AM

Thanks for your reply. I read the Using ADO.Net section on MSDN and several articles on how to use datasets, etc. That's where I got what I have in my program. I just looked at the other link you gave me and will see if that fix works for me. I thought I had changed "TableAdapter" to DataSet after I typed that. Apparently not. Once I have the dataset full, the rest will be reading the values.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1