Posts

Donate

Convert Or Cast MySQL Database Column Collation In SQL Code And C#

Software Used: Mysql 5.0 connector/Visual Studio 2010 We encounter a tricky problem when showing mysql database column value with collation of typelatin1_swedish_ci. The value retrieved from the column and shown on a c# string variable is not the same with what is in the database. The ascii characters has been stripped off in the string variable. Here is a string variable with special character apostrophe stored in a column with latin1swedish collation. Ex. Take on bank robbers, beat the bad guys or shoot it out with the police in the quest for freedom – all in the name of fun! Doesn’t sound like your average day out, but today we’re making this happen! string sql = "select convert(description using utf8) as description from your_table where id='554be79124998120b8c3505d47c88c2d'" ; Sample C# Implementation private void TestDeals() { DataTable dt = new DataTable(); string conn_s = ConfigurationManager.AppSettings[ "LocalDB" ]; stri

Show Processes From Your Computer Using ASP.NET Web Forms

Here's a sample code on how to display processes using Process.GetProcesses() method from Process class and bind it to the GridView Control. Code behind: protected void ShowProcessToGrid() { Dictionary< string , string > process = new Dictionary< string , string >(); foreach (Process p in Process.GetProcesses()) { process.Add(p.Id.ToString(),p.ProcessName); } this .gvPRocess.DataSource = process; this .gvPRocess.DataBind(); } protected void gvPRocess_PageIndexChanging( object sender, GridViewPageEventArgs e) { gvPRocess.PageIndex = e.NewPageIndex; ShowProcessToGrid(); } Here is the aspx markup: <asp:GridView ID= "gvPRocess" runat= "server" AllowPaging= "True" BackColor= "White" BorderColor= "Black" BorderStyle= "Solid" BorderWidth= "1px" CellPadding= "4" style= "margin:auto"

Return First Array In Array Object That Has Duplicates In C#

Here's a custom function that returns the first array item that has duplicates in an array object. //in your main function #region testdata //string[] split_cities = new string[] { "perth", "sydney", "perth" }; //string[] split_cities = new string[] { "perth", "sydney", "gold" }; //string[] split_cities = new string[] { "nsw", "sydney", "sydney" }; //string[] split_cities = new string[] { "nsw", "nsw", "sydney" }; //string[] split_cities = new string[] { "nsw", "coast", "sydney", "nsw" }; //string[] split_cities = new string[] { "auck", "coast", "nsw", "nsw" }; string [] split_cities = new string [] { "auck" , "nsw" , "nsw" , "coasts" }; //string[] split_cities = new string[] { "auck", "coast&

Draggable Window In WPF Using C#

In my WPF application, the opacity of the window has been set to transparent and the ResizeMode has been set to No Resize. This application has a user control as child element. When the window is renedered on screen, i can't drag the object/window in my screen. So to do this, you have to check the mouse down event in your windows. Then call the DragMove method. Here is the snippet: void Window_MouseDown( object sender, MouseButtonEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) this .DragMove();

Add Control Dynamically To Grid in WPF Using C#

To add a child control to a Grid Layout, simply call the Add() method in Children of the grid control. Label lbl = new Label(); lbl.Content = "1" ; grdClock.Children.Add(lbl); Where: grdClock is the Grid control

SQL Retrieve Or Count Record On A Previous Date In MySQL

Here's a simple demonstration of sql in MySQL where you can retrieve a record from a previous date. select sum (data_gathered) as data_gatherer, name from tblctivity where name like '%prgGatherer1.xml%' and (date(rec_date) = (CURDATE() - 1));

How To Check Nulls In MySQL Database Table

Assuming QuantityPerUnit is the field to be tested. -- return products with no null values select * from products where QuantityPerUnit is not null ; -- return products with null values select * from products where isnull (QuantityPerUnit);

Using Microsoft.VisualBasic DateDiff() Function In Your C# Program

Below is a snippet on how to use the Microsoft.VisualBasic DateDiff() Function in your C# program. Add the Microsoft.VisualBasic reference to your project so that you can access it's underlying classes and methods. long age = Microsoft.VisualBasic.DateAndTime.DateDiff( "yyyy" ,Convert.ToDateTime( "1985-04-04" ),DateTime.Now);

How To Decode An Encoded URL In C#.NET

The code below illustrates how to decode an encoded url using HttpUtility.UrlDecode(string url) using System.Web; //make sure to add reference to System.Web string temp_url = "http%3a%2f%2fplacement.emploiquebec.net%2f" + "mbe%2fut%2fsuivroffrs%2fapercoffr.asp" + "%3fnooffr%3d3053675%26page%3drech%26prov% 3derechroffr%252Easp%26CL%3denglish "; string url = HttpUtility.UrlDecode(temp_url);

Read Or Parse XML Using XmlElement Class, XPath And XmlNodelist In C#

Sample xml file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <?xml version="1.0" encoding="UTF-8"?> <jobs> <job> <title> Payroll Analyst </title> <description> <summary> Seeking Payroll Analyst specialists. Great benefits and competitive salary. Must meet all requirements to be considered for assignment. </summary> </description> <location> <state> Pennsylvenia </state> </location> </job> <job /> </jobs> Code: 1 2 3 4 5 6 7 8 9 10 11 ListingSource = webclient.DownloadString( "your_xmlurl" ); StringReader readString = new System.IOStringReader(ListingSource); XmlDocument awesome = new XmlDocument(); awesome.Load(readString); XmlNodeList nodeList = awesome.SelectNodes( "//jobs/job" ); foreach (XmlElement element in nodeList) { title = elem

Donate