Reputation: 429
I am writing a wpf application which pulls data from a sql db.
Currently I'm using the following code to populate a couple of text fields in my Window.
I would like to change this to get the data from the Entity Framework model (which I have implemented) instead of filling a dataset from a stored procedure first.
// Initialize a new Data Set object
DataSet dts = new DataSet();
DataTable dt = new DataTable();
// Call the DataManager Class which will collect the data and fill the dataset
DataManager.SelectConsHead(dts);
dt = dts.Tables[0];
// Set the source of the listview
foreach(DataRow drr in dt.Rows)
{
txtAccount.Text = drr["Consignee"].ToString();
txtAccount_Printed.Text = drr["Consignee_Printed"].ToString();
txtPostalAdd1.Text = drr["Postal_Add1"].ToString();
txtPostalAdd2.Text = drr["Postal_Add2"].ToString();
txtPostalAdd3.Text = drr["Postal_Add3"].ToString();
txtPostalAdd4.Text = drr["Postal_Add4"].ToString();
}
}
Upvotes: 0
Views: 1953
Reputation: 5691
I think you need to learn the Entity framework.
here you can learn by videos provided by team.
sample code.
using (var db = new BloggingContext())
{
// Create and save a new Blog
Console.Write("Enter a name for a new Blog: ");
var name = Console.ReadLine();
var blog = new Blog { Name = name };
db.Blogs.Add(blog);
db.SaveChanges();
// Display all Blogs from the database
var query = from b in db.Blogs
orderby b.Name
select b;
Console.WriteLine("All blogs in the database:");
foreach (var item in query)
{
Console.WriteLine(item.Name);
}
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
Upvotes: 3