From this Business World .Net components is essential for developing Web Applications.
Before creating .NET Components we need to declare a Business class.
See this example.
using System;
using System.Data;
using System.Data.SqlClient;
namespace BANK{
public class BankAccount {
private string m_AccountNumber;
public BankAccount () {
m_AccountNumber=”";
}
public BankAccount (string AccountNumber) {
m_AccountNumber = AccountNumber;
}
public string DatabaseConnection {
set { m_AccountNumber = value; }
get { return m_AccountNumber; }
}
public DataSet GetAccounts (string AccountType) {
if (m_AccountNumber == “”)
{
throw new ArgumentNullException(“DatabaseConnection”,
“No value for the database connection string”);
}
SqlConnection myConnection = new SqlConnection(m_AccountNumber);
SqlDataAdapter sqlAdapter1 = new SqlDataAdapter(
“SELECT * FROM Accounts WHERE AccountType=’”+AccountType+”‘”, myConnection);
DataSet Accounts = new DataSet();
sqlAdapter1.Fill(Accounts, “Accounts”);
return Accounts;
}
public DataSet GetAccountTypes () {
if (m_AccountNumber == “”)
{
throw new ArgumentNullException(“DatabaseConnection”,
“No value for the database connection string”);
}
SqlConnection dbConnection = new SqlConnection(m_AccountNumber);
dbConnection.Open();
SqlDataAdapter sqlAdapter1 = new SqlDataAdapter(
“SELECT DISTINCT AccountType FROM Accounts”, dbConnection);
DataSet types = new DataSet();
sqlAdapter1.Fill(types, “ProdTypes”);
return types;
}
}
}
For Combiling this sample class,we need to type the below statement in Command Prompt.
csc /out:binBANK.dll /t:library sampleObject.cs /r:System.Data.dll
/r:System.dll /r:System.XML.dll
After we need to try this component in ours webpage
using BANK —We accessing the Developed Component,Don,t forget to referencing BANK Component.
BANK.BankAccount objbankAccount = new BANK.BankAccount();
Now we can utilize any methods using objbankAccount.
Cheers
Hope this helps you better
Happy Coding!
Comments are closed.