Skip to main content

Posts

Showing posts with the label C#

Dynamically create Bar Chart using Chart.js in Asp.net

This article explains about Bar Chart. We are going to create a simple Bar Chart using char.js library in jQuery. Bar Chart can be used to show data or compare multiple data sets. Chart.js : A Simple chart library for developers developed by Nick Downie . It uses HTML5 canvas element and supports all the browsers.  Code Snippet Code Behind Finally, we are done with coding. You can bind a real dataset from the code behind and see the output Happy Coding :)

jQuery Dialog for ASP.NET

A jQuery dialog is a lightweight pop-up which can be used in ASP.NET to get the confirmation from the user before doing some task. Here I shall demonstrate how to work with jQuery dialog in ASP.NET. First of all we need to import the jQuery core and UI libraries in the head section of the master page Then add the jQuery dialog to the page Now we will design the popup and the buttons Code behind Happy Coding :)

Method Overriding with C#

Method overriding is a feature that allows you to invoke functions (that have the same signatures) that belong to different classes in the same hierarchy of inheritance. Let's understand method overriding using few examples. Output Above code consists of base class A and a derived class B. Class A consists of method Show(). Class B hides the function Show() it inherited from the base class A by providing its on implementation of Show(). In the above code we first created object of type A. Using the reference variable “a” we invoke the function Show(). As expected,  Show() of class A is executed because the reference variable “a” refers to the object of class A. Then we created an object of Derived class B and storing its reference in the reference variable “a” of type A. Using the reference variable “a” we invoke the function Show(). Since “a” contains a reference to an object of type B we would expect the function Show() of class B to get executed. But that do...

Validating DropDownList using RequiredFieldValidator

In ASP.NET we need to validate DropDownList controls. But validating the DropDownList control with RequiredFieldValidator is not a straight forward as validating a TextBox control with RequiredFieldValidator. It requires little extra work. Following are the steps for validating a  DropDownList  with  RequiredFieldValidator Step 1: Create a DropDownList control 1: < asp:DropDownList ID ="ddlFruit" runat ="server" Height ="22px" Width ="200px" > 2: < asp:ListItem > - Select - </ asp:ListItem > 3: < asp:ListItem > Apple </ asp:ListItem > 4: < asp:ListItem > Orange </ asp:ListItem > 5: < asp:ListItem > Banana </ asp:ListItem > 6: < asp:ListItem > Pineapple </ asp:ListItem > 7: </ asp:DropDownList > Step 2: Add a RequiredFieldValidator 1: < asp:RequiredFieldValidator ID ="rfvFruit" runat =...

Get the BIOS Serial Number with C#

Fisrt you have to import the following referenece in to your project. System.Management Sample Code 1: using System; 2: using System.Management; 3: using System.Windows.Forms; 4:   5: namespace DemoProjects 6: { 7: public partial class frmBIOSSerial : Form 8: { 9: public frmBIOSSerial() 10: { 11: InitializeComponent(); 12: } 13:   14: private void btnGet_Click( object sender, EventArgs e) 15: { 16: string serialNumber = string .Empty; 17:   18: ManagementObjectSearcher MOS = new ManagementObjectSearcher( " Select * From Win32_BIOS " ); 19: foreach (ManagementObject getserial in MOS.Get()) 20: { 21: serialNumber = getserial[ "SerialNumber" ].ToString(); 22: } 23:   24: lblSerialNumber.Text = serial...

Displaying a PDF file within a WPF application

I had a need to view PDF files directly within a WPF application for a projcect.So i found an easy way to do that.The trick is to use the WinForms support in WPF ala the WindowsFormHost control.

Beginning XML with C# 2008

Book Description Beginning XML with C# 2008 focuses on XML and how it is used within .NET 3.5. As you’d expect of a modern application framework, .NET 3.5 has extensive support for XML in everything from data access to configuration, from raw parsing to code documentation. This book demystifies all of this. It explains the basics of XML as well as the namespaces and objects you need to know in order to work efficiently with XML. You will see clear, practical examples that illustrate best practices in action. With this book, you’ll learn everything you need to know from the basics of reading and writing XML data to using the DOM, from LINQ and SQL Server integration to SOAP and web services. Here are a few of the topics you'll learn The basics of XML in .NET 3.5 Validating and transforming XML Using XML with LINQ Integrating with ADO.NET, SQL Server, and WCF Configuring the .NET Framework with XML Book Details Paperback: 600 pages Publisher: ...

Animate Windows Form

In this tutorial, I will briefly explain how to add animation effects to a windows form in C#. In order to animate a window in C#, we will need to call a native method using PInvoke.   Create a new Windows Forms Project AnimateWindow Function According to the MSDN Library, "the animate window function enables you to produce special effects when showing or hiding windows". There are only four types of animation that you can use. They are: roll, slide, collapse/expand, and alpha-blended fade. In order to call the AnimateWindow function, as already stated, we need to use PInvoke. This is the PInvoke signature for the AnimateWindow function (the using System.Runtime.InteropServices ; declaration is required)   Add this to the top of the "Form1" class. [DllImport("user32.dll")] static extern bool AnimateWindow(IntPtr hWnd, int time, AnimateWindowFlags flags); Notice the "AnimateWindowFlags" parameter. This is a user-defined t...

Head First C#, 2nd Edition

Product Description You want to learn C# programming, but you’re not sure you want to suffer through another tedious technical book. You’re in luck: Head First C# introduces this language in a fun, visual way. You’ll quickly learn everything from creating your first program to learning sophisticated coding skills with C# 4.0, Visual Studio 2010 and .NET 4, while avoiding common errors that frustrate many students. The second edition offers several hands-on labs along the way to help you build and test programs using skills you’ve learned up to that point. In the final lab, you’ll put everything together. From objects to garbage collection and from exceptions to interactions, you’ll learn C# in a way that engages and entertains your brain.   Here are a few of the topics you’ll learn: Start by building a useful application with pre-built components in Visual Studio 2010 Discover how objects work, using real-world examples Store numbers, text, and other ba...

Retrieve SQL Table Column data into a Array

When I was searching how to “Retrieve SQL Table Column data into an Array”, I found many ways to do that. But I was not happy about those solutions. So I searched for it so many times. Finally today I found a way to do that easily. So I thought to share with you all.   public static string [] Genre() { string Query = "SELECT <Column Name> FROM <Table Name>"; SqlConnection ConnObj = new SqlConnection(Connection()); ConnObj.Open(); SqlCommand CommObj = new SqlCommand (Query, ConnObj); SqlDataReader Reader = CommObj.ExecuteReader(); string [] TempArray = new string [200]; int Name = Reader.GetOrdinal( "Name" ); //Gets the column ordinal, given the name of the column. int i = 0; while (Reader.Read()) { TempArray[i] = Reader.GetString(Name); i++; } Reader.Close(); return TempArray; } This function will return an array of the values.You can use it anyway you want….

Run a SQL Script at runtime of a C# application

In my previous post I explained how to run a SQL Script using Command prompt. It is bit difficult. So I found a way to run the SQL script using the application. I used it on button click. Here is how I did it. 1.   Create your SQL Script. 2. Add the references below to your C# application using Microsoft.SqlServer.Server; using Microsoft.SqlServer.Management.Smo; using Microsoft.SqlServer.Management.Common; using Microsoft.SqlServer.Management.Sdk.Sfc; 3. Add the path to your SQL Script string Filename = Path .Combine( Environment .GetFolderPath( Environment . SpecialFolder .MyDocuments) + "\\Configuration\\" , "Create_Database.sql" ); 4. Add the code below to read your SQL Script StreamReader StreamReader;           StreamReader = new StreamReader (Filename); string CreateDBQuery = StreamReader.ReadToEnd(); 5. Create a connection with server & Execute Query string tempConnString= "Data Source=(local);Inte...