AccessDataSource Select Command

J

Jim McGivney

In VS'05 I have an aspx page with a label that I am trying to populate from
a field (Last) in table (Ante_Pedigree) from an Access database.

In C# in a code-behind I run:

AccessDataSource AccessDataSource2 = new AccessDataSource();
AccessDataSource2.DataFile =
System.Configuration.ConfigurationManager.AppSettings["ConnString"];
Parameter Param = new Parameter("AnteNum");
Param.DefaultValue = fileid;
AccessDataSource2.SelectParameters.Add(Param);
AccessDataSource2.SelectCommand = "SELECT Last FROM Ante_Pedigree Where
AnteNum=@Param";
LabelFileNum.Text =
AccessDataSource2.Select(DataSourceSelectArguments.Empty).ToString();



The result is that LabelFileNum.Text = System.Data.DataView

What am I doing wrong; I am obviously using an advanced feature when all I
want to do is retrieve a value.

Thanks in advance for your help.

Jim
 
N

Neutrino

The ToString() method is returning System.Data.DataView because that is
the type of the object returned by the Select member of
AccessDataSource .

You may need to cast to a DataView to then retrieve the record you
need:

LabelFileNum.Text =
((DataView)AccessDataSource2.Select(DataSourceSelectArguments.Empty))[0]["Last"].ToString();

Hope this helps.
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top