C-Sharp code and Programming Concept
     
 
User Name Password validation using C-sharp code
public string Affiliate_Login(string username, string password)
{
string result="";
objdbaccess.ConnectDB();
SqlDataReader myReader = objdbaccess.ExecuteQuerybyReader("Select Affiliate_ID,Affiliate_Status from tbl_Affiliate where Affiliate_Email='"+ username +"' AND Affiliate_Password='"+ password + "' AND Affiliate_Status='1'");
if (myReader.HasRows)
{
while (myReader.Read())
{
if (myReader.HasRows==true && myReader[1].ToString()=="1")
{
result="Active";
}
else
{
result="In Active";
}
}
}
else
{
result="Not Found";
}

objdbaccess.CloseDBConnect();
return result;
}

       
       
     
Inserting Data in Table using C-Sharp code
public string Affiliate_Save(string FirstName,
string LastName, string AgreementFlag,
string EmailAddress,string Password,string
BusinessName,string Address,string City,
string State,string Country,
string Phone,string Website,
string PayPalAccountID,string ZipCode)

{

try
{
string ConnString=System.Configuration.ConfigurationSettings.AppSettings["ConxnString"];
SqlConnection SConnection=new SqlConnection(ConnString);
SConnection.Open();

string result="";

SqlCommand myCommand = new SqlCommand("usp_SaveAffiliate",SConnection);
myCommand.CommandType = CommandType.StoredProcedure;


myCommand.Parameters.Add("@FirstName",SqlDbType.NVarChar,50);
myCommand.Parameters["@FirstName"].Value = FirstName;

myCommand.Parameters.Add("@LastName",SqlDbType.NVarChar,50);
myCommand.Parameters["@LastName"].Value = LastName;

myCommand.Parameters.Add("@Email",SqlDbType.NVarChar,50);
myCommand.Parameters["@Email"].Value = EmailAddress;

myCommand.Parameters.Add("@Password",SqlDbType.NVarChar,50);
myCommand.Parameters["@Password"].Value = Password;

myCommand.Parameters.Add("@Bussiness",SqlDbType.NVarChar,50);
myCommand.Parameters["@Bussiness"].Value = BusinessName;

myCommand.Parameters.Add("@Address",SqlDbType.NVarChar,50);
myCommand.Parameters["@Address"].Value = Address;

myCommand.Parameters.Add("@City",SqlDbType.NVarChar,50);
myCommand.Parameters["@City"].Value = City;

myCommand.Parameters.Add("@ZipCode",SqlDbType.NVarChar,6);
myCommand.Parameters["@ZipCode"].Value = ZipCode;

myCommand.Parameters.Add("@Phone",SqlDbType.NVarChar,20);
myCommand.Parameters["@Phone"].Value = Phone;

myCommand.Parameters.Add("@Country",SqlDbType.NVarChar,2);
myCommand.Parameters["@Country"].Value = Country;

myCommand.Parameters.Add("@State",SqlDbType.NVarChar,50);
myCommand.Parameters["@State"].Value = State;

myCommand.Parameters.Add("@Website",SqlDbType.NVarChar,50);
myCommand.Parameters["@Website"].Value = Website;

myCommand.Parameters.Add("@PayPalID",SqlDbType.NVarChar,100);
myCommand.Parameters["@PayPalID"].Value = PayPalAccountID;

myCommand.Parameters.Add("@Agreement",SqlDbType.Char,1);
myCommand.Parameters["@Agreement"].Value = AgreementFlag;

myCommand.Parameters.Add("@SignupDate",SqlDbType.DateTime);
myCommand.Parameters["@SignupDate"].Value = System.DateTime.Now.ToString();

myCommand.Parameters.Add("@ActivationDate",SqlDbType.DateTime);
myCommand.Parameters["@ActivationDate"].Value = "1/1/1900";

myCommand.Parameters.Add("@Status",SqlDbType.Char,1);
myCommand.Parameters["@Status"].Value = "0";


//myCommand.ExecuteNonQuery();
SqlDataReader myReader = myCommand.ExecuteReader();
if (myReader.HasRows==true)
{
while (myReader.Read())
{
result= myReader[0].ToString();
}
}
else
{
result = "0";
}

SConnection.Close();
return result;
}
catch(Exception ex)
{
return ex.Message;
}

}

       
     
Selecting Data from Database on load event using C-Sharp code
private void Page_Load(object sender, System.EventArgs e)
{

objdbaccess.ConnectDB();
SqlDataReader myReader = objdbaccess.ExecuteQuerybyReader("Select State_Name from tbl_State");
ddState.Items.Add("Select State");
if (myReader.HasRows==true)
{
while (myReader.Read())
{
ddState.Items.Add(myReader[0].ToString());
}
}
else
{
ddState.Items.Add("States Unavailable");
}
objdbaccess.CloseDBConnect();
objdbaccess.ConnectDB();
SqlDataReader CountryReader = objdbaccess.ExecuteQuerybyReader("select Country_Name from tbl_Country");

ddCountry.Items.Add("Select Country");
if (CountryReader.HasRows==true)
{
while (CountryReader.Read())
{
ddCountry.Items.Add(CountryReader[0].ToString());
}

}
else
{
ddCountry.Items.Add("Countries Not Available");

}

objdbaccess.CloseDBConnect();


}
 
 
     
           
   
Calling Class method on Button Click event
private void btnLogin_Click(object sender, System.EventArgs e)
{
string Aff_ID = objAffiliate.Affiliate_Login(txtAffiliateID.Text,txtAffiliatePassword.Text);
if (Aff_ID=="In Active")
Session["AffiliateID"] = Aff_ID;
Response.Redirect("Affiliate_Personalized.aspx");

}

 
 
     
   
Stored Procedure for inserting data in SQL TABLE
CREATE PROC usp_SaveAffiliate
@FirstName nvarchar(50),
@LastName nvarchar(50),
@Email nvarchar(50),
@Password nvarchar(50),
@Bussiness nvarchar(50),
@Address nvarchar(50),
@City nvarchar(50),
@ZipCode nvarchar(6),
@Phone nvarchar(20),
@Country nvarchar(2),
@State nvarchar(50),
@Website nvarchar(50),
@PayPalId nvarchar(100),
@Agreement char(1),
@SignupDate datetime,
@Activationdate datetime,
@Status char (1)

AS
DECLARE @AffiliateID int

Select affiliate_email from tbl_Affiliate where affiliate_email=@Email
if @@Rowcount = 0
BEGIN
Insert into tbl_Affiliate
(Affiliate_Email,
Affiliate_Password
,Business_Name,
Affiliate_Address,
Affiliate_City,
Affiliate_Zip,
Affiliate_Phone,
Affiliate_Country,
Affiliate_State,
Affiliate_Primary_Website,
Affiliate_PayPal_ID,
Affiliate_Agreement,
Affiliate_Signup_Date,
Affiliate_Activation_Date,
Affiliate_Status)

Values (@Email ,
@Password ,
@Bussiness ,
@Address ,
@City ,
@ZipCode ,
@Phone ,
@Country ,
@State,
@Website ,
@PayPalId ,
@Agreement ,
@SignupDate ,
@Activationdate,
@Status )

SET @AffiliateID = (Select Affiliate_ID from tbl_Affiliate WHERE Affiliate_Email=@Email)
Select Affiliate_ID from tbl_Affiliate WHERE Affiliate_Email=@Email
END
GO

 
 
     
Stored Procedure for URL validation
CREATE PROCEDURE dbo.usp_IsWebsiteExist
@URL nvarchar(200) AS DECLARE @Result int
Select URL from tbl_entries where URL like '%www.' + @URL +'%'
if @@rowcount > 0
SET @Result='1'
else
SET @Result = '0'
Select @Result
GO
Paging of Data Grid using C#

 

Step #1 Make four Asp.net Buttons with Label First , Previous , Next ,Last

<asp:Button id="Button6" runat="server" Text="First" CommandArgument="3"Onclick="PagingMeth()"></asp:Button>


<asp:button id="Button3" runat="server" Text=" Prev " CommandArgument="0"Onclick="PagingMeth()></asp:button>


<asp:button id="Button4" runat="server" Text=" Next" CommandArgument="1"Onclick="PagingMeth()></asp:button>


<asp:button id="Button5" runat="server" Text=" Last " CommandArgument="2" Onclick="PagingMeth></asp:button>

Step # 2 In the CS file of that Pagingpage.aspx write the method PagingMeth()

private void PagingMethod(object sender,System.EventArgs e)
{
try
{
Button btn = (Button)sender;
int arg = Convert.ToInt32(btn.CommandArgument);
switch (arg)

{
case 0:
if(OrdersGrid.CurrentPageIndex <(OrdersGrid.PageCount-1)) //Previous Page Logic
OrdersGrid.CurrentPageIndex +=1;
break;

case 1:
if (OrdersGrid.CurrentPageIndex >= 0) //Next Page Logic

OrdersGrid.CurrentPageIndex -=1;
break;
case 2:
OrdersGrid.CurrentPageIndex =(OrdersGrid.PageCount-1); //Last Page Logic
break;
case 3:
OrdersGrid.CurrentPageIndex = 0; //First Page Logic
break;
}
BindData();
}
catch(Exception ee)
{
string ete= ee.Message;
}
}

Step # 3 : Make a method of BindData() to Bind the DataGrid data

protected void BindData()

{

string sqlQuerr = "Select * from tablename";

OrdersGrid.DataBind();

}

Also need to make a method in which DataSet is populating the DataGrid


             
   
             
 
© Copyrights ideallogics.com. all rights reserved.