Amit Kumar on .Net 2.0./3.0./3.5.

This is the right place to discuss about WPF and XAML.Come and join with me to share more idea about this amazing technology.

Subscribe to RSS feed

How can we get the MAC Address in C# Application.

To fetch or get the MAC Address in C# application we have to use ” Win32_NetworkAdapterConfiguration” WMI class. This class represent the attributes and behavior of the network adapter card. This class includes extra properties and methods that support the management of the TCP/IP and Internetwork Packet Exchange (IPX) protocols that are independent from the network adapter.
These are the list of the Properties of the “Win32_NetworkAdapterConfiguration” class.
boolean ArpAlwaysSourceRoute;
boolean ArpUseEtherSNAP;
string Caption;
string DatabasePath;
boolean DeadGWDetectEnabled;
string DefaultIPGateway[];
uint8 DefaultTOS;
uint8 DefaultTTL;
string Description;
boolean DHCPEnabled;
datetime DHCPLeaseExpires;
datetime DHCPLeaseObtained;
string DHCPServer;
string DNSDomain;
string DNSDomainSuffixSearchOrder[];
boolean DNSEnabledForWINSResolution;
string DNSHostName;
string DNSServerSearchOrder[];
boolean DomainDNSRegistrationEnabled;
uint32 ForwardBufferMemory;
boolean FullDNSRegistrationEnabled;
uint16 GatewayCostMetric[];
uint8 IGMPLevel;
uint32 Index;
uint32 InterfaceIndex;
string IPAddress[];
uint32 IPConnectionMetric;
boolean IPEnabled;
boolean IPFilterSecurityEnabled;
boolean IPPortSecurityEnabled;
string IPSecPermitIPProtocols[];
string IPSecPermitTCPPorts[];
string IPSecPermitUDPPorts[];
string IPSubnet[];
boolean IPUseZeroBroadcast;
string IPXAddress;
boolean IPXEnabled;
uint32 IPXFrameType[];
uint32 IPXMediaType;
string IPXNetworkNumber[];
string IPXVirtualNetNumber;
uint32 KeepAliveInterval;
uint32 KeepAliveTime;
string MACAddress;
uint32 MTU;
uint32 NumForwardPackets;
boolean PMTUBHDetectEnabled;
boolean PMTUDiscoveryEnabled;
string ServiceName;
string SettingID;
uint32 TcpipNetbiosOptions;
uint32 TcpMaxConnectRetransmissions;
uint32 TcpMaxDataRetransmissions;
uint32 TcpNumConnections;
boolean TcpUseRFC1122UrgentPointer;
uint16 TcpWindowSize;
boolean WINSEnableLMHostsLookup;
string WINSHostLookupFile;
string WINSPrimaryServer;
string WINSScopeID;
string WINSSecondaryServer;

Note:- The “Win32_NetworkAdapterConfiguration” class is present under the System.Management Namespace. So before using the “Win32_NetworkAdapterConfiguration” class you must add the refrence of System.Management namespace in your project.

Here is the a function written in c#, that return the MAC address of the system

private string GetMacAddress()
{
string macid = string.Empty;
ManagementClass mac = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection macObjCol = mac.GetInstances();
foreach (ManagementObject mo in macObjCol)
{
if (macid.Equals(string.Empty))
{
if ((bool)mo["IPEnabled"] == true)
{
macid = mo["MacAddress"].ToString();
mo.Dispose();
}
}
}
return macid;
}
Used Namespace
System.Management
;

Convert DataSet to RecordSet

Hi, Friends
I am going to express a new topic which is more intresting , the topic is how we convert a ADO.Net DataSet to ADO RecordSet.
I need this conversion, when we are working BI-Reporting Application. In this project we have a third party control, its name is TeeChart6.0. control. That control takes a record set not the Dataset. When we try to pass the DataSet to TeeChart control it fires a COM Exception so, I need this conversion.

Before doing the conversion from DataSet to RecordSet , you must take the refrence of the ADOB library version 7.0.3300.0.

Now we post the complete code of it.
For doing this we create three function
1. bool CheckIntDataTpye(Type colType) : It check for the DataType
2. static ADODB.Recordset ConvertDsToRs(DataTable inTable):- It convert the DS to RS.
3. static ADODB.DataTypeEnum TranslateColumnType(Type columnType):- It is for DataTypeEnum.
Function Body
1.
private bool CheckIntDataTpye(Type colType)
{
switch (colType.UnderlyingSystemType.ToString())
{
case "System.Int16":
return true;
case "System.Int32":
return true;
case "System.Int64":
return true;
case "System.SByte":
return true;
case "System.Byte":
return true;
case "System.Decimal":
return true;
case "System.Double":
return true;
case "System.Single":
return true;
case "System.UInt16":
return true;
case "System.UInt32":
return true;
case "System.UInt64":
return true;
default:
return false;
}
}

Function Body
2.
public static ADODB.Recordset ConvertDsToRs(DataTable inTable)
{
ADODB.Recordset result = new ADODB.Recordset();
result.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
ADODB.Fields resultField = result.Fields;
System.Data.DataColumnCollection inColumns = inTable.Columns;
foreach (DataColumn inColumn in inColumns)
{
resultField.Append(inColumn.ColumnName, TranslateColumnType(inColumn.DataType), inColumn.MaxLength, inColumn.AllowDBNull ? ADODB.FieldAttributeEnum.adFldIsNullable : ADODB.FieldAttributeEnum.adFldUnspecified, null);

}
result.Open(System.Reflection.Missing.Value, System.Reflection.Missing.Value, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic, 0);
foreach (DataRow dr in inTable.Rows)
{
result.AddNew(System.Reflection.Missing.Value, System.Reflection.Missing.Value);
for (int colIndex = 0; colIndex < inColumns.Count; colIndex++)
{
resultField[colIndex].Value = dr[colIndex];
}
}



return result;
}
Function Body
3.
private static ADODB.DataTypeEnum TranslateColumnType(Type columnType)
{
switch (columnType.UnderlyingSystemType.ToString())
{
case "System.Boolean":
return ADODB.DataTypeEnum.adBoolean;

case "System.Byte":
return ADODB.DataTypeEnum.adUnsignedTinyInt;

case "System.Char":
return ADODB.DataTypeEnum.adChar;

case "System.DateTime":
return ADODB.DataTypeEnum.adDate;

case "System.Decimal":
return ADODB.DataTypeEnum.adCurrency;

case "System.Double":
return ADODB.DataTypeEnum.adDouble;

case "System.Int16":
return ADODB.DataTypeEnum.adSmallInt;

case "System.Int32":
return ADODB.DataTypeEnum.adInteger;

case "System.Int64":
return ADODB.DataTypeEnum.adBigInt;

case "System.SByte":
return ADODB.DataTypeEnum.adTinyInt;

case "System.Single":
return ADODB.DataTypeEnum.adSingle;

case "System.UInt16":
return ADODB.DataTypeEnum.adUnsignedSmallInt;

case "System.UInt32":
return ADODB.DataTypeEnum.adUnsignedInt;

case "System.UInt64":
return ADODB.DataTypeEnum.adUnsignedBigInt;

case "System.String":
default:
return ADODB.DataTypeEnum.adVarChar;
}

}

Note:- Used Namespaces
using System.Data.SqlClient;
using System.Data;

Difference between ADO.Net DataSet and ADO RecordSet

,

1.Recordset provides data one row at a time.
Dataset is a data structure which represents the complete table data at same time.

2.Recordset has the logic to update and manipulate data.
Dataset is just a data store and manipulation is done through DataAdapters in .NET.

3.Dataset Disconnected architecture.
Record Set Connected Architecture.

4.With Data set you can retrive data from database like oracle and SQL Server and manage them in one dataset, with recordset this is not possible.

5. All representation of Dataset is using XML while recordset uses COM.

6. The Recordset was not XML-based and could not be serialized to XML easily or flexibly.

7. Recordset can not be transmitted on HTTP while Dataset can be.

8. A DataSet can represent an entire relational database in memory, complete with tables, relations, and views.

9. A DataSet is designed to work without any continuing connection to the original data source.

10. Data in a DataSet is bulk-loaded, rather than being loaded on demand.

11. There's no concept of cursor types in a DataSet.

12. DataSets have no current record pointer You can use For Each loops to move through the data.

13. You can store many edits in a DataSet, and write them to the original data source in a single operation.

14. Though the DataSet is universal, other objects in ADO.NET come in different versions for different data sources.




XMLDataBinding and ListView Control In WPF Application

May 2012
S M T W T F S
April 2012June 2012
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