Posts

Showing posts from February, 2012

Donate

Webbrowser Control Not Displaying Webpage (No Internet Connection Message)

In one of our codes, we used web browser to scrape data. Recently, the webbrowser control can't display the webpage. The error states that THERE IS NO INTERNET CONNECTION. The solution was to Clear History of Internet Explorer Browser..(cookies/passwords/forms/temporary internet files) Cheers!

Set JSON Response In Webrequest Class

To set the JSON response of a WebRequest class, assign the ContentType property of the WebRequest object to application/json; charset=utf-8 . req.ContentType = "application/json; charset=utf-8" ; Source: Stackoverflow

Attach MSSQL DB To SQL Developer Edition On Runtime

If you have a program migrated to a pc where there is no sql express edition installed but a developer or enterprise edition is found and the database is part of the solution file. If you run the program, a connection timeout error will occur. All you need to do is change the datasource name from .\sqlexpress to your Servername. Then change the credentials such as username and password. Assuming you declare your connection string in app.config or web.config, here is an example: <add name= "Southridge.Properties.Settings.SouthridgeConnectionString" connectionString= "Data Source=PC_SERVERNAME; AttachDbFilename=|DataDirectory|\Southridge.mdf;user=sa; password=yourpassword; Connect Timeout=30;" providerName= "System.Data.SqlClient" />

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

Donate