This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Me And My Respected Teacher Mr Kamal Sheel Mishra

Mr. K.S. Mishra is HOD of Computer Science from SMS Varanasi where I have completed my MCA

Me And My Respected Teacher Mr Udayan Maiti

Mr. Udayan Maiti is a senior .Net Expert and has guided many professionals of multi national Companies(MNC)

Me And My Best Friend Mr Ravinder Goel

Mr. Ravinder Goel is a senior Software Engineer and now he is working Wipro Technology

Monday, 28 October 2013

Class in C# .Net

Class in C# .Net

Class: Class is nothing but a blue print or template. Classes are reference types and they get allocated on heap. It is user defined data type that used to contains different items like

·         Data Field
·         Member  Function
·         Property
·         Constructor
·         Delegates
·         Event
·         Attribute
·         De Constructor
·         Indexer

Class Theory: There are two type class theories 
·         Within Class
·         Outside of class

Rules  of Object Oriented Programming:
·         To access data field and member function of class we have to create object of class
·         Procedure  to create object of class
·         Every object  create separate memory block
·         Keyword this  is  the owners of the class


General Syntax to create a Class object:
<Class Name> <object name>=new <Class Name> ();

 For Example: Class1 c1=new Class1 ();
Or
  <Class Name> <object name>;
  <Object name>=new <Class Name> ();

       For Example: Class1 c1;
              c1=new Class1 (); 

Note: we can access public region with the help of object directly but we cannot access private region directly


Example With Class:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ClassExample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

public class Class1
{
private int a, b;
public int c;

public void SetData()
{
a = 5;
b = 7;
c = 9;
}
}
private void button1_Click(object sender, EventArgs e)
{

Class1 ob1 = new Class1();
ob1.SetData();
ob1.c = 10;

//ob1.a=25  // we cannot initialized a ,because a is private member
//ob1.b=34;

}
}
}

  

Saturday, 26 October 2013

How to create Dynamic Query for Optional Search in ADO.NET without any If else Condition

How to create Dynamic Query for search in ADO.NET without any  If else Condition


--create database sqltopquery
use sqltopquery

--create table MyFriendList in database sqltopquery  

create table MyFriendList(SrNo int identity(1,1) primary key,Name nvarchar(50),Emailid nvarchar(50) unique ,MobileNo nvarchar(50)unique,Address nvarchar(50),Course nvarchar(50))

--insert  into table  
insert into MyFriendList values('Kush Tiwari','kushktiwari@gmail.com','9451119029','Ghazipur','M C A')

Code  For  Insert Data in Table………………………………………………..

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Drawing;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnSave_Click(object sender, EventArgs e)
{
try
{
SqlConnection con = new SqlConnection(@"Data Source=KUSH-PC\KUSH;Initial Catalog=sqltopquery;Integrated Security=True");
SqlCommand cmd = new SqlCommand("insert into MyFriendList values('" + txtname.Text + "','" + txtemailid.Text + "','" + txtmobileno.Text + "','" + txtaddress.Text + "','" + ddlcourse.SelectedItem.Text + "')", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
lblmessage.Visible = true;
lblmessage.ForeColor = Color.Green;
lblmessage.Text = "Save Successfully";
}
catch (Exception ex)
{
lblmessage.Visible = true;
lblmessage.ForeColor = Color.Green;
lblmessage.Text = ex.Message;
}
}
}



--Code  for Search from table with any condition(using dynamic query) without any if else condition

Source code  for Search.aspx ………………………………………………..

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Search.aspx.cs" Inherits="Search" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 70%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<table class="style1" >
<tr>
<td>
Search By Name</td>
<td>
Search By EmailId</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtemailid" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Search By Mobile No</td>
<td>
Search By&nbsp; Course</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtmobileno" runat="server"></asp:TextBox>
</td>
<td>
<asp:DropDownList ID="ddlcourse" runat="server" Height="19px" Width="126px">
<asp:ListItem>--Select--</asp:ListItem>
<asp:ListItem>M C A</asp:ListItem>
<asp:ListItem>B C A</asp:ListItem>
<asp:ListItem>B Tech</asp:ListItem>
<asp:ListItem>M Tech</asp:ListItem>
<asp:ListItem>M A</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
Search&nbsp; By Address</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtaddress" runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnSearch" runat="server" onclick="btnSearch_Click"
Text="Search" />
</td>
</tr>
<tr>
<td colspan="2"><center>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</center>
</td>
</tr>
</table>
<div>
</div>
</form>
</body>
</html>

Source code  for Search.aspx.cs ………………………………………………..

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class Search : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnSearch_Click(object sender, EventArgs e)
{

// using ternary-operator……………………………………..

SqlConnection con = new SqlConnection(@"Data Source=KUSH-PC\KUSH;Initial Catalog=sqltopquery;Integrated Security=True");

string qry = "Select * from MyFriendList Where 1=1";

qry += txtname.Text.Trim() != "" ? (" And Name = '" + txtname.Text.Trim()) + "'" : "";

qry += txtaddress.Text.Trim() != "" ? (" And Address = '" + txtaddress.Text.Trim()) + "'" : "";

qry += txtmobileno.Text.Trim() != "" ? (" And MobileNo = '" + txtmobileno.Text.Trim()) + "'" : "";

qry += txtemailid.Text.Trim() != "" ? (" And Emailid = '" + txtemailid.Text.Trim()) + "'" : "";

qry += ddlcourse.SelectedIndex != 0 ? (" And Course = '" + ddlcourse.SelectedItem.Text.Trim()) + "'" : "";

SqlDataAdapter da = new SqlDataAdapter(qry, con); ;
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();

}
}




--What is ternary operator