Home » Archive

Articles in the C# Codes Category

ASP.Net, C# Codes, Tech Corner »

[27 Oct 2009 | No Comment | Posted By:Vivek]

Here i will explain the binding of a treeview from the Database.This can be a tricky task since we may have to build a parent-child relationship here.So first thing you would need is a table in the database where we actually have the parent-child relationship.
An Example
Table Name: Category
CategoryId  INT
CategoryName  Varchar(50)
ParentCategoryId INT
NodeLevel  INT
Suppose we have Data in the Table named Category as follows

1
Root
NULL
0

2
Child
1
1

3
Child2
1
1

4
grandChild
2
2

5
grandChild2
2
2

6
grandChild3
3
2

//

Now to bind this to the tree,we will use a recursive function.Also for better performance,we will bind the database results into a global DataTable first and then apply filtering.
Here is the Code …

Read the full Post »

ASP.Net, C# Codes, Tech Corner »

[6 Oct 2009 | No Comment | Posted By:Vivek]

There may be many instances in which we may have to supply a string in CSV format to be converted into an integer array.For example,if we have to invoke a web method in a web service in which the parameters to be passed is an integer array.There is no way that we can pass an Integer array to the web method,else you would have to have a client application to test the method.Well,this was the instance in which i had the need to pass these integers in CSV format as …

Read the full Post »

ASP.Net, C# Codes, Tech Corner »

[5 Oct 2009 | One Comment | Posted By:Vivek]

Serialization is a process by which information in an object is converted into a persistable and transportable form.Here i will explain the easiest way to do XML Serialization,which converts (serializes) the public fields and properties  of an object, or the parameters and return values of methods, into an XML stream that conforms to a specific XML Schema definition language (XSD) document.
To explain the basics of serialization,lets create a class Product containing information about a Product
Public Class Product()
{
public product(){ }
public string productName;
public float productPrice;
}
Now to create an XML representation of the object …

Read the full Post »

C# Codes, Tech Corner »

[4 Jun 2009 | No Comment | Posted By:Lloyd]

“DBAccess” class(Download code)
                For making the sqlserver connection easier a user defined class “DBAccess.cs” is used in which all the database activities are done.The “GetTable( )” will help you execute a select query.This method returns a DataTable “dt” .Now there is another method called “ExecuteQuery( )“, which also takes as input a string,this method is used to execute insert and update queries.Eventhough both methods can be used interchangably i prefer this way,because the “ExecuteQuery( )” returns an integer value which will give us …

Read the full Post »

C# Codes, Tech Corner »

[25 Mar 2009 | No Comment | Posted By:Vivek]

Getting the Ip address of the local machine
using system.net;

string strHostName = string.Empty;

cmbIPAddress.Items.Clear();//combo box to hold the ip address

strHostName = Dns.GetHostName();//get name of the local machine

IPHostEntry ipEntry = Dns.GetHostByName(strHostName);
IPAddress[] iparrAddr = ipEntry.AddressList
if (iparrAddr.Length > 0)
{
for (int intLoop = 0; intLoop < iparrAddr.Length; intLoop++)
cmbIPAddress.Items.Add(iparrAddr[intLoop].ToString());
}
Getting the ip addresses of machines connected through LAN

First Get the names of the machines
using System.Net;
using System.Diagnostics;
using System.IO;

Process netUtility = new Process();

netUtility.StartInfo.FileName = “net.exe”;
netUtility.StartInfo.CreateNoWindow = true;
netUtility.StartInfo.Arguments = “view”;
netUtility.StartInfo.RedirectStandardOutput = true;
netUtility.StartInfo.UseShellExecute = false;
netUtility.StartInfo.RedirectStandardError = true;
netUtility.Start();

StreamReader streamReader = new StreamReader(netUtility.StandardOutput.BaseStream, netUtility.StandardOutput.CurrentEncoding);

string line = “”;
while ((line = streamReader.ReadLine()) != null)
{
if (line.StartsWith(”\\”))
{
cmbnetworkcomputers.Items.Add(line.Substring(2).Substring(0, line.Substring(2).IndexOf(” …

Read the full Post »