Subhash Sharma

Subhash Sharma
Subhash Sharma

This is Subhash Sharma(Software Engineer) Blog

Welcome to this blog and find every solution.............

Search This Blog

Software Engineer(Subhash Sharma)

Software Engineer(Subhash Sharma)
Software Engineer

Friday, March 12, 2010

connectionstring

connectionStrings
add name ="Master1" connectionString ="Data Source=OKH;database=leave; user id =sa; pwd="/
/connectionStrings

Connection String

//Connection String



Fill DropDown

SqlConnection con = new
//Connection String



//Page Load Code here

SqlConnection(ConfigurationManager.ConnectionStrings["Master1"].ConnectionString);
SqlCommand cmd;
SqlDataAdapter adp;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
con.Open();
cmd = new SqlCommand("Select category_id,category_name from tbl_category order by category_id", con);
adp = new SqlDataAdapter(cmd);
ds = new DataSet();
adp.Fill(ds);
if (ds.Tables[0].Rows.Count != 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
drpCategory1.Items.Add(ds.Tables[0].Rows[i]["Category_Name"].ToString());
drpCategory1.Items[i + 1].Value = ds.Tables[0].Rows[i]["Category_id"].ToString();

}
}
ds.Dispose();
adp=null;
con.Close();
}
}

Work with RSS

protected void Page_Load(object sender, EventArgs e)
{

Response.AppendHeader("refresh", "10");
// XmlTextReader reader = new XmlTextReader("http://cricket.ndtv.com/cricket/ndtvcricket/rssnews/ndtv/cat/news/rss.html");
DataSet ds = new DataSet();
ds.ReadXml(reader);
GridView1.DataSource = ds.Tables[3];
GridView1.DataBind();

}

Validate the contorl in java script

function Validate()
{
if (document.getElementById("Name").value == "") //"Name" == it is a control Id
{
alert("Please enter name");
return false;
}

if (document.getElementById("address").value == "")
{
alert("Please enter Address");
return false;
}
if (document.getElementById("contactno").value == "")
{
alert("Please enter contact no");
return false;
}
if (document.getElementById("query").value == "")
{
alert("Please enter Query");
return false;
}
return true;

}

// Show the salary sum according to the dept wise

SELECT Tbl_Emp.empname, Tbl_Emp.salary AS Amount, TBL_Dept.Deptname
FROM Tbl_Emp INNER JOIN
TBL_Dept ON Tbl_Emp.deptid = TBL_Dept.Deptid
order BY deptname desc
COMPUTE SUM(salary) BY deptname

Threading

public void ThreadJob()
{
for (int i = 0; i < 10; i++)
{
MessageBox.Show(i.ToString());
Thread.Sleep(1000);
}
}
public void ThreadJob1()
{
for (int i = 0; i < 10; i++)
{
MessageBox.Show(i.ToString());

Thread.Sleep(2000);
}
}
private void button2_Click(object sender, EventArgs e)
{
ThreadStart job = new ThreadStart(ThreadJob);
ThreadStart job1 = new ThreadStart(ThreadJob1);
Thread thread = new Thread(job);
Thread thread1 = new Thread(job1);
thread.Start();
thread1.Start();
}

Events and Delegates

//Delegate is handler for the event. Delegate work without event but Event can't work without Delegate because Delegate work as a handler for Event.

Car on = new Car();
private void car_Change()
{
MessageBox.Show("Tankempty");
}
private void sum(int a, int b)
{
MessageBox.Show("Tankempty");
}
private void car_Change1()
{
MessageBox.Show("TankFull");
}

private void button1_Click(object sender, EventArgs e)
{
on.Change += new Car.ChangingHandler(car_Change);
on.Change1 += new Car.ChangingHandler(car_Change1);
on.SetTank(int.Parse(textBox1.Text));



}

//Class

public class Car
{
private int tank;

// delegate declaration
public delegate void ChangingHandler();

// event declaration
public event ChangingHandler Change;
public event ChangingHandler Change1;

public Car()
{

}

public void SetTank(int p)
{
this.tank = p;
// call the event
if (p < 51)
{
Change();
}
else
{
Change1();
}
}

public string GetTank()
{
return this.tank.ToString();
}
}

Show the javascript box in .cs fle

string s = "";
ClientScript.RegisterStartupScript(this.GetType(), "aa", s);

Find the control from gridview

TextBox txtName = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtName");
TextBox txtCity = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtCity");
Label lbnlid = (Label)GridView1.Rows[e.RowIndex].FindControl("lblId");
Label lbnlid = (Label)GridView1.Rows[e.RowIndex].FindControl("lblId");
Posted by DeepakSinghRawat at 9:15 PM
Labels: Label lbnlid = (Label)GridView1.Rows[e.RowIndex].FindControl("lblId");

Insert the values in GridView1_RowCancelingEdit

protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
fillgridview();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
fillgridview();
}

delete duplicate data from Table

Note : You must have (Identity key) (EmpId) field in the table.

DELETE
FROM emp
WHERE empID NOT IN
(
SELECT MAX(empID)
FROM emp
GROUP BY empname)