Posts

Showing posts from 2014

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!

ListView In WPF With Alternating Row Colors

Here's how to alternate the row colors for a WPF ListView control using a Converter class and Triggers. Converter Class: 1 2 3 4 5 6 7 8 9 10 11 12 13 public class AddressTargetConverter : IValueConverter { public object Convert( object value , Type targetType, object parameter, CultureInfo culture) { return ( value .ToString().Equals(parameter.ToString())); } public object ConvertBack( object value , Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } XAML: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 <Window.Resources> <y:AddressTargetConverter x:Key= "AddressTargetConverter" /> </Window.Resources> <Grid> <StackPanel> <ListView ItemsSource= "{Binding PersonCollection}" > <ListView.It

ASP.NET GridView Control CRUD With Bootstrap

Image
Here's a simple CRUD application using ASP.NET GridView control with Twitter Bootstrap as it's css class reference. The code sample used is in VB.NET. Create: Update: Delete: ASPX markup: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 <div id= "Container" > <div id= "GridContainer" > <div id= "LabelContainer" > <asp:Label ID= "lblHeading" runat= "server" Text= "ASP.NET GridView CRUD with Bootstrap (VB.NET)" > </asp:Label>

ASP.NET GridView RowCommand Event Firing Twice

This issue happened when I migrated an asp.net 3.5 website to an asp.net 4.5 website. Upon clicking Add or Delete linkbuttons in the GridView, the RowCommand event fires twice. After googling for hours, I found a solution that is to remove the Handles GridView1.RowCommand in the event declaration. The code below does not work (event fires twice) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Protected Sub GridView1_RowCommand ( ByVal sender As Object , ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) _ Handles GridView1.RowCommand If e.CommandName.Equals( "AddNew" ) Then Dim txtNewName As TextBox txtNewName = CType (GridView1.FooterRow.FindControl( "txtNewName" ), TextBox) Dim cmbNewGender As DropDownList cmbNewGender = CType (GridView1.FooterRow.FindControl( "cmbNewGender" ), DropDownList) Dim txtNewCity As TextBox txtNewCit

Find Checked Treenode In TreeView Control Using LINQ In VB.NET

Here's one way of searching through a treenode using LINQ. Assuming that the search criteria is a List or array object. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 Public Class Form1 Public Shared mat As List( Of String ) = Nothing Private Sub Form1_Load (sender As System.Object, e As System.EventArgs) Handles MyBase .Load mat = New List( Of String ) mat.Add( "Books" ) mat.Add( "VB" ) mat.Add( "Drinks" ) mat.Add( "Food" ) mat.Add( "Tea" ) mat.Add( "Chod" ) End Sub Private Sub Button1_Click (sender As System.Object, e As System.EventArgs) Handles Button1.Click If Not (mat Is Nothing ) Then For Each tn As String In mat If (tvMat.Nodes.Find(tn, True ).FirstOrDefault() IsNot Nothing ) Then If (tvMat.Nodes

The type of one of the expression in the join clause is incorrect.Type inference failed in the call to GroupJoin In C#

Hi, I just tested on grouping two collections using GroupJoin approach in LINQ to XML. In the example, the two collections are Customers and Companies. In which, companies served as grouping for the customers. In simple terms, identify a customer of which company he or she belongs. The code below produced an error The type of one of the expression in the join clause is incorrect.Type inference failed in the call to GroupJoin. XElement companiesAndCustomers = new XElement( "CompaniesAndCustomers" , from company in companies join customer in customers on company equals customer.CompanyName into groupCompany select new XElement( "Company" , new XAttribute( "CompanyName" , company.CompanyName), new XAttribute( "Country" , company.Country), from subCustomer in groupCompany select new XElement( "Customer" , subCustomer.LastN

Formatting ASP.NET Web Forms Panel as Bootstrap Modal Dialog

Here's how you make use of the asp.net panel container that will serve as modal dialog. During render, panel will be converted to div elements. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 <asp:Panel ID= "pnlModal" runat= "server" role= "dialog" CssClass= "modal fade" > <asp:Panel ID= "pnlInner" runat= "server" CssClass= "modal-dialog" > <asp:Panel ID= "pnlContent" CssClass= "modal-content" runat= "server" > <asp:Panel runat= "server" class= "modal-header" > <button type= "button" class= "close" data-dismiss= "modal" > <span aria-hidden= "true" > &times; </span><span class= "sr-only" > Close </span> </button>

WIndows Forms Linear Gradients In C#.NET 2D

Image
Hi, Here's a simple demo using Linear gradients (Color Manipulation) in C#.NET Windows Forms. private int _rColor = 100; public int GenerateRGB( int cc) { int rt = 0; if (cc <= 255) { rt = Information.RGB(255, cc, 0); } else if (cc < 511) { rt = Information.RGB(255 - (cc - 255), 255, 0); } else if (cc < 766) { rt = Information.RGB(0, 255, cc - 511); } else if (cc < 1022) { rt = Information.RGB(0, 255 - (cc - 767), 255); } else if (cc < 1277) { rt = Information.RGB(0, 0, 255 - (cc - 1022)); } else { rt = Information.RGB(0, 0, 0); } return rt; } private void timer1_Tick( object sender, EventArgs e) { this .Refresh(); _rColor += 1; if (_rColor > 1500) { _rColor = 0; } } private void Form1_Paint( object sender, PaintEventArgs e) { Color color = new Color(); Random m_Rnd = new Random(); color = Color.FromArgb(255, m_Rnd.Next(0, 255), m_Rnd.Next(0, 255), m_Rnd.Next(0, 255)); using (LinearGradi

Cannot connect to WMI provider. You do not have permission or the server is unreachable In SQL Server 2012

Image
Hello, When you click on SQL Server Configuration Tools after pc reboot, you might encounter an error stated by the title of this post. Given the following details OS: Windows 7 Enterprise 64 Bit Software: SQL Server 2012 Network Setup: Domain Controller The steps to resolve the issue is presented below: 1. Right click command prompt and select "Run as Administrator" 2. Type the following in the command prompt C:\ mofcomp "%programfiles(x86)%\Microsoft SQL Server\110\Shared\sqlmgmproviderxpsp2up.mof" (where 110 is the number) Note: For this command to succeed, the Sqlmgmproviderxpsp2up.mof file must be present in the %programfiles(x86)%\Microsoft SQL Server\number\Shared folder. Sample Error Message: Cheers! :)

ASP.NET Web Forms Using Master Page Not Found On Visual Studio 2012 IDE

When the RTM versions of Visual Studio 2012 were updated to version 4, I noticed that when you Add a New Item in an Asp.net website or project, "Web Form Using Master Page" has gone missing. I soon realized that Web Form Using Master Page is replaced with "Content Page" in the Add New Item Dialog. :)

Webbrowser Control Imitate Internet Explorer Behavior

Image
Hi, Lately, I was given a task from a client if I can update my VB.NET crawler scripts with a webbrowser control to show/render images of the crawled website to the control. Normally, I used the control just to obtain the web page source and then parse the necessary information. By default, the settings of the webbrowser control is IE7. After doing some reseach, I stumbled upon a solution by Noseratio on IE Feature Control Hacks . The documentation for browser emulation can be found on MSDN: MSDN Browser Emulation . I uploaded a sample VB.NET application here: WebBrowser Control Similar to IE Browser Sample Result: Cheers! :)

List Running Computer Processes By Array Names Using LINQ In C# And VB.NET

Image
Here's a snippet on how to retrieve running process in your computer by array names using LINQ. C# Code 1 2 3 4 5 6 7 8 List<Process> procs = new List<Process>(); procs = new List< string >() { "firefox" , "iexplore" , "ssms" , "notepad++" , "chrome" } .SelectMany(o => Process.GetProcessesByName(o)).ToList(); foreach ( var item in procs) { Console.WriteLine(item.ProcessName); } VB.NET 1 2 3 4 5 6 Dim procs As IEnumerable( Of Process) = _ { "firefox" , "iexplore" , "ssms" , "notepad++" , "chrome" }.SelectMany(Function(proc) Process.GetProcessesByName(proc)) For Each p In procs Console.WriteLine(p.ProcessName) Next Console.ReadLine() Output

WPF DataGrid Row And Cells Extension Methods In VB.NET

Image
Below are extension methods in accessing WPF DataGrid Rows and Cells. These methods were based on existing C# methods and I converted them to VB.NET for VB programmers. WPF DataGrid Extension Methods: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 Option Explicit On Option Infer On Imports System.Runtime.CompilerServices Imports System.Windows.Controls.Primitives

Show Asterisk Triangle Shapes Using TSQL In SQL Server

Image
In programming, it's a common exercise to show triangle shapes using the asterisk character. Well, this can be achieved using TSQL as well. Script #1 DECLARE @Total1 INT DECLARE @ctrOuter1 INT DECLARE @ctrInner1 INT DECLARE @strPrint1 VARCHAR(100) SET @Total1 = 5 SET @ctrOuter1 = @Total1 SET @strPrint1 = '' WHILE @ctrOuter1 >= 1 --outer loop BEGIN SET @strPrint1 = '' SET @ctrInner1 = 0 WHILE @ctrInner1 <= (@Total1 - @ctrOuter1) BEGIN SET @strPrint1 = @strPrint1 + '*' SET @ctrInner1 = @ctrInner1 + 1 END PRINT @strPrint1 SET @strPrint1 = @strPrint1 + CHAR(13) SET @ctrOuter1 = @ctrOuter1 - 1 END Output: Script #2 DECLARE @Total INT DECLARE @ctrOuter INT

Databinding ASP.NET 4.5 GridView With jQuery And Ajax

Image
Hi, Here's a simple asp.net program that performs adding of data to GridView control through jQuery and ajax. On page load, perform databinding on dropdown list and gridview using server side and code behind. And on client side, that is a selection change occurs in dropdown list, perform binding by adding table rows and columns to GridView. Page Load (Load All Products): Selection Change (Load Specific Products): The sample code is available for download here: Databinding ASP.NET 4.5 GridView with jQuery and Ajax Code Cheers!

GeckoFX DocumentText Similar To Webbrowser Control Alternative (C#)

In this post GeckoFX DocumentText similar to Webbrowser , I presented a solution on how to retrieve the page source of a website. However, another solution was provided by a .NET guru using TextContent property: this .Document.GetElementsByTagName( "html" )[0].TextContent; Cheers!

How To Paint Or Set WPF DataGridCell Background Without Using IValueConverter

Here's how to paint WPF DatagridCell using extension methods without using IValueConverter. Extension Method: 1 2 3 4 5 6 7 8 9 10 11 12 Module DataGridExtensions < Extension() > Function GetRow ( ByVal grid As DataGrid, ByVal index As Integer ) As DataGridRow Dim row As DataGridRow = DirectCast (grid.ItemContainerGenerator.ContainerFromIndex(index), DataGridRow) If row Is Nothing Then grid.UpdateLayout() grid.ScrollIntoView(grid.Items(index)) row = DirectCast (grid.ItemContainerGenerator.ContainerFromIndex(index), DataGridRow) End If Return row End Function End Module MainWindow.xaml: 1 2 3 4 Dim firstRow As DataGridRow = grid1.GetRow( 0 ) 'grid1 is your DataGrid control Dim firstColumnInFirstRow As Controls.DataGridCell = DirectCast (grid1.Columns( 0 ).GetCellContent(firstRow).Parent, Controls.DataGridCell) 'set background firstColumnInFirstR

Split A String With Multiple Space As Delimiter Or Separator Using Regular Expression Or String.Split In C# and VB.NET

Given that you have a string that you want to split and the separator is two or more spaces. You can achieve using split() or Regex. VB.NET 1 2 3 4 5 6 7 8 Dim str As String = "Rule Name: WhosThere-176.44.28.203" Dim whosThereVar As String Dim whosThereString As String 'using split whosThereVar = str.Split( New String () { " " }, StringSplitOptions.RemoveEmptyEntries)( 1 ).Trim() 'using regex whosThereString = System.Text.RegularExpressions.Regex.Split(str, "\s{2,}" )( 1 ) C# 1 2 3 4 5 string str = "Rule Name: WhosThere-176.44.28.203" ; //using split string whosThereVar = str.Split( new string [] { " " }, StringSplitOptions.RemoveEmptyEntries)[ 1 ].Trim(); //using regex string whosThereString = System.Text.RegularExpressions.Regex.Split(str, @"\s{2,}" )[ 1 ];

Sorting A HashTable Object Using LINQ In C#.NET And VB.NET

Image
In .NET, you can't directly sort a Hashtable object. A tip on sorting a Hashtable object is to cast it to Dictionary then apply LINQ OrderBy() method to the Hashtable object. See examples below: VB.NET 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 Private Sub SortHashTableKey () hash = New Hashtable() hash.Add( "B" , 1 ) hash.Add( "A" , 2 ) hash.Add( "C" , 3 ) Dim dict = hash.Cast( Of DictionaryEntry)() _ .ToDictionary(Function(d) d.Key, Function(d) d.Value) _ .OrderBy(Function(e) e.Key) Console.WriteLine( "Sort by Key" ) For Each item In dict.ToList() Console.WriteLine( String .Format( "{0}, {1}" , item.Key, item.Value)) Next Console.WriteLine(Environment.NewLine) End Sub Private Sub SortHashTableValue ()

Donate