Posts

Showing posts with the label ADO.NET

Donate

The file references an XML namespace that is inconsistent with the target framework of the project. (Entity Framework 6)

Good day to all! When adding an ADO.NET Entity Data Model to a ASP.NET project which connects to a certain SQL Server database, the entities (tables) do not appear on the model design view. However, the model successfully connects to the SQL DB.Upon checking the Model design view, an error is shown which is "The file references an XML namespace that is inconsistent with the target framework of the project.". After debugging and re-doing the steps in adding Entity Data Model, the error still persists. Later, I found out that the ASP.NET project target framework was 4.0. Changing it to .NET Framework 4.5 solved the issue . Cheers!

Retrieve Last Inserted Record In MySQL Database Using C#.NET

To get last inserted unique ID in MySQL, use LAST_INSERT_ID(). C# Code: 1 2 3 4 string insert_product_query = ( "INSERT INTO PRODUCTS (Stock) VALUES (5); SELECT LAST_INSERT_ID()" ); MySqlCommand cmd_query = new MySqlCommand(insert_product_query, objConn); int idResult = Convert.ToInt32(cmd_query.ExecuteScalar()); txtID.Text = idResult.ToString(); MySQL Docs: Getting Last Unique ID in MySQL

Using AutoMapper In Asp.Net Web Forms Database Application

Image
Hello, Based from Scott Millet's Asp.Net Design Patterns , I was curious on the AutoMapper Framework that maps Domain Entities to View Models. So I tried to give it a spin by incorporating the tool in an ASP.NET WebForms application. Here's the code snippets breakdown: Order class: /// <summary> /// One order may contain one or many order details. /// </summary> public class Order { public int OrderId { get ; set ; } public DateTime OrderDate { get ; set ; } public DateTime RequiredDate { get ; set ; } public string ShipName { get ; set ; } public string ShipAddress { get ; set ; } public IList<OrderDetails> OrderDetail { get ; set ; } } Order View class: public class OrderView { public int OrderId { get ; set ; } public DateTime OrderDate { get ; set ; } public DateTime RequiredDate { get ; set ; } public string ShipName { get ; set ;

Include Foreign Key Columns In The Model Disabled (ADO.NET Entity Framework)

When adding database objects to your entity data model, The checkbox option labeled (Include foreign key columns in the model) might be disabled. I later found out that the class library's target framework was .NET 3.5 Framework. While the solution and asp.net website's target framework is .NET 4.0. The solution was to change the target framework to .NET 4.0 then recompiled the class library. Alas! the include foreign key columns is now enabled. Cheers!

.NET 4.5 Framework Features

Image
Here's an image i got from  http://muralitharan.info  blog. Thanks to the guy who uploaded this image... :) Greg

How To Sort DataTable In C# Or VB.NET

Sorting a data table before binding to a data control like gridview or datalist is provided by microsoft through it's predefined methods which is defaultview.sort. Example: //C# dt1.DefaultView.Sort = "Name Desc" ; //VB.NET dt1.DefaultView.Sort = "Name Desc" Where dt1 is your datatable. Or you could create a dataview object as provided by MSDN. Source: MSDN

Simple WPF Datagrid Demo Or Tutorial

I have developed a project on WPF before. WPF has been utilized in Vista OS and other software. But this cannot replace the stability of Windows Forms. Still, I don't have ample time to dive deeply in WPF, hopefully soon! LOL.. :D So, to begin with: 1. Download and install WPF Toolkit (Visual Studio 2008) 2. Open Visual Studio 2008 3. Add a WPF Project (Just call it GridDemo) 4. Add a DataGrid in your Window.xaml 5. Make sure to have referenced wpf toolkit: http://schemas.microsoft.com/wpf/2008/toolkit/ 6. Customize Your Grid <grid:DataGrid AutoGenerateColumns= "False" Margin= "8,11,10,78" ItemsSource= "{Binding}" Name= "CusGrid" > <grid:DataGrid.Columns> <grid:DataGridTextColumn Binding= "{Binding Path=CustomerID}" Header= "Customer ID" /> </grid:DataGrid.Columns> ....other columns goes here </grid:DataGrid> 7. In your Window1.cs file, populate your gr

How To Reorder Or Rearrange DataColumns In A DataTable Using C#

Here's how to re-order DataColumns in a DataTable. This solves a particular problem in a project I'm currently working with. Code: 1 datatable.Columns[ "Col1" ].SetOrdinal( 1 );

ADO.NET Entity Framework Tutorial

Here's an example from MSDN. There are some minor bugs that I encountered, but this is a good start. ADO.NET Entity Framework in Winforms

Donate