1
Answer

Getting data from a dataset

Ask a question
Scott Stewart

Scott Stewart

12y
1.7k
1
This is very frustrating!

            string strAccessCon=@"Provider=Microsoft.Ace.OLEDB.12.0;" +
                @"Data Source=C:\Users\Scot\Documents\Landman\NewLandman.accdb";
            DataSet thisDataSet=new DataSet();
            OleDbConnection thisCon=new OleDbConnection(strAccessCon);
            OleDbDataAdapter daTracts =new OleDbDataAdapter();
            string thisTract = tractNo.Substring(6);
            string strSQL = "Select TractName, TractID, SurveyID, TractDescription FROM tblTracts WHERE TractName='" + @thisTract +"'";
            OleDbCommand selectCmd=new OleDbCommand(strSQL, thisCon);
            daTracts.SelectCommand=selectCmd;
            daTracts.Fill(thisDataSet,"tblTracts");
            DataTable myTable = thisDataSet.Tables[0];
            if (myTable.Rows.Count>0)
            {
                int rowCount = myTable.Rows.Count;
               tractName= myTable.Rows[0].ToString();
            }

So I found out there is one row (as it should be). So where are the values I need? I have tried all sorts of different lines to extract the values from the table. I would rather just get it from the Dataset, but I have not been able to find any documentation on how to do it. MSDN site doesn't help.
I need to know how to access the columns in the row.

Answers (1)