2 Replies - 12262 Views - Last Post: 14 October 2009 - 08:20 AM Rate Topic: -----

#1 Philipman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-March 09

Filling DataGrid/Listview with Access Database

Posted 14 October 2009 - 04:19 AM

Hi guys

I have been using Windows Forms up until now and am starting with WPF. I am using Visual C# Express 2008.

I have used the Add Data Source wizard to add an Access Database to my file. In WinForms I simply drag a DataGrid onto the form and it asks me what database I want to fill it. I select the one i just added and it works splendidly. I can use LINQ to easily access and manipulate the data. When I check the code it has generated this appears:

  private void Form1_Load(object sender, EventArgs e)
		{
			
			this.tblMoviesTableAdapter.Fill(this.moviesDataSet.tblMovies);

		}



Now to my problem: I simply cannot get the database into WPF. I have tried a listview with code similar to what appears above. I have downloaded the WPF Toolkit, which has a Datagrid, and i still simply cannot get my database into the damn grid/listview etc. so that I can view or manipulate data.

What is the declaration code for outside databases? Is it a XAML binding? I have tried that too but can't get it to work. The name of the database is Movies.accdb.


I have searched the internet exhaustively for any answer, and also checked the 2 books on WPF i have (WPF Unleashed and WPF in Action). However, I simply cannot find a simple tutorial that shows one how to import an Access Database into WPF and use LINQ to manipulate and view data!

If someone could help me I'd greatly appreciate it.

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Filling DataGrid/Listview with Access Database

#2 olibenu  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 45
  • View blog
  • Posts: 536
  • Joined: 31-December 08

Re: Filling DataGrid/Listview with Access Database

Posted 14 October 2009 - 06:10 AM

might not be as easy. try this or just download this and start coding (after converting here). the class returns an arraylist after reading the table, you can then use it to fill your grid/listview. an example of how i use it (first of all do declare myDB as DB datatype:
public class Players : System.Collections.Generic.List<Player>
{
	public bool DBReadAll()
	{
		this.Clear();
		myDB.Type = DBType.ACCESS;
		myDB.Path = DBPath;
		{
			if ((myDB.Connect & myDB.Open)) {
				ArrayList alPlayers = new ArrayList();
				ArrayList alDetails = new ArrayList();
				alPlayers = myDB.Read(tblPlayer);
				this.Clear();
				int i = 0;
				for (i = 0; i <= alPlayers.Count - 1; i++) {
					Player aPlayer = new Player();
					alDetails = alPlayers(i);
					{
						aPlayer.Id = alDetails(0);
						aPlayer.Name = alDetails(1);
						aPlayer.Team = alDetails(2);
						aPlayer.Goals = alDetails(3);
						aPlayer.IsInjured = alDetails(4);
						aPlayer.RedCards = alDetails(5);
						aPlayer.YellowCards = alDetails(6);
					}
					this.Add(aPlayer);
				}
				myDB.Close();
				return true;
			}
			else {
				Interaction.MsgBox("Player - DB Error");
				return false;
			}
		}
	}
}

This post has been edited by olibenu: 14 October 2009 - 06:21 AM

Was This Post Helpful? 0
  • +
  • -

#3 Philipman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 09-March 09

Re: Filling DataGrid/Listview with Access Database

Posted 14 October 2009 - 08:20 AM

Thanks a lot, will give all of those suggestions a go!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1