Showing posts with label confusing. Show all posts
Showing posts with label confusing. Show all posts

Monday, March 26, 2012

Newbie Access Database Question

I'm just starting to learn ASP.net, I have a lot of ASP experience, which probably makes ASP.net even more confusing. Basically what I'm trying to do is read data from an access database and then repeat a certain format until the last database entry. I'll give an example

Database has 5 columns: Section, Author, Title, Link, Bibiography

Website:

Section
Author, Title (linked), Bibiography
...
Author...
Section
Author...

Make sense?

This would be very easy in asp, but I haven't quite gotten the grasp of .netSuggestion: Forget ASP. Yeah it stinks to start over, but it's easier that way.

the 'dot net way':

Grab the data into a data set. Check out theTutorials (linked above). There are also a ton of other sites out there for accessing data from a database with .NET. Search for '.NET + Access + DataSet'.

Once you have it in a DataSet object the rest is sooooo easy. Just setup a repeater object on the page. Then an 'item template' and define how you want each item to look like. Lastly add a seperator template if you want something between records. Finally in the code section do MyRepeater.DataSource = MyDataSet.Tables(0) *your data, then MyRepeater.DataBind() and you'll be all set. If you want tabular data without too crazy of formatting, check out the DataGrid. If you just want to list the results in columns you do the DataSource line from above (except you use a DataGrid object) and the DataBind method call. The rest is automagic.

If you need help with the data access, check out the Access forum in the Data Discussions section.

-Ryan
You can use a Repeater, DataList, or DataGrid for this purpose. This tutorial might be helpful:Binding to Data Display Controls. See also the Tutorials section of this site (in particularData Access and Customization). I think a DataList might suit your purposes pretty well, or a Repeater if you need more control (but also requires more coding).

Terri
thanks for the quick responces...

I looked up how to use the repeater control and it seems like this is what I'm looking for. Is the best way to group all of the same sections together to make an if statment? Is that legal within a repeater? Here's what a sample database looks like

General, Blah, Blah
General, Blah2...
Science, Blah3...
Science, Blah4...

I'd like it to:

General
blah
blah2
Science
blah3
blah4

Thanks for all your help
I think you want to put a Order By clause in your SQL Query.


Select Section, Author, Title, Link, Bibiography from MyDB
Order By Section, Author DESC

This will return
General, bob, bobs book, xxx, xxxx
General, sarah, sarahs book, xxx, xxxx
General, tim, tims book, xxx, xxxx
Science, joe, joes book, xxx, xxx

It first sorts Section alphabetically and then within all matching sections it then sorts on the author.

Newbie confusion with MS .net IDE

I was hoping someone could help me with some things I'm finding rather confusing. I recently migrated from command-line c# development to using Visual Studio .net.

1) The IDE seems to use HTTP to access the files in my project, but when one attempts to add an existing file to a project it uses standard file io. Thus, one is required to have both types of connectivity to a directory where one is doing work, which from my perspective kind of obviates the whole point of the HTTP requirement in the first place. How can I turn this HTTP functionality off? Any logic I can think of that supports the case for HTTP was dashed in the bit bucket when I came across the standard file io requirement for adding existing files. Any light that one could shed on this issue would be great.

2) When I moved a directory containing a project and its associated files from one web server to another, and then opened up the project, all the .cs files associated with my .aspx (these are all in the same directory as the project) disappeared. Why? This is very confusing and really annoying.

Does anyone have any idea how I can go back to the old IDE that I'm used to, or make the new one behave in the ways that I'm accustomed to?I don't know about your first question, but for the second one... try this...

There is an icon in the 'solution explorer' view in VS.net that will show all files in the project. (I had the same thing happen when moving a project, and this made the hidded code behind files visible. For some reason, VS.net did not want to show all the files by default after the move.)

- Jigster