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

Wednesday, July 28, 2010

Fetch Master Page value

Page mypage = (Page)this.Page;
MasterPage mp = (MasterPage)mypage.Master;
Label lab = (Label)mp.FindControl("lblVersionHeader");

Update Query with join

// Without condition

UPDATE C INNER JOIN A ON C.Empid = A.Empid SET A.Empname =C.Empname

//With Condition

UPDATE C INNER JOIN A ON C.Empid = A.Empid SET A.Empname = C.Empname
WHERE (((A.Empname)="w"));

Bind Combo Through XML

XmlDocument xml = new XmlDocument();
// xml.LoadXml(@"c:\abc.xml"); // suppose that myXmlString contains "..."
xml.Load(@"c:\abc.xml");
XmlNodeList xnList = xml.SelectNodes("/NewDataSet/Table");
foreach (XmlNode xn in xnList)
{
string firstName = xn["Sno"].InnerText;
string lastName = xn["CustomerName"].InnerText;
DropDownList1.Items.Add(lastName);
DropDownList1.Items[0].Value = firstName;
}

Fetch Value Through UserControl (.ascx file)

//ADC is a user controlName wich we will add in @response directive

//Ex:(Inline Code) %@ Register TagName ="ABC" TagPrefix ="ABC" Src="~/WebUserControl.ascx"%>
after that you can add where u want......
ABC:ABC ID="ADC" runat="server" />

.cs (Code Behind)

WebUserControl we;
we = (WebUserControl)this.FindControl("ADC");
TextBox txtuser = (TextBox)we.FindControl("txtname");
TextBox txtpassword = (TextBox)we.FindControl("txtPassword");

Transaction in .Net(Insert Data through Stored Procedure)

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Master"].ConnectionString);
SqlTransaction tran=null ;
SqlCommand cmd;
SqlDataAdapter adp;
DataSet ds;

try
{
con.Open();
tran=con.BeginTransaction();



cmd = new SqlCommand("InserData", con);

cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("Name", txtName.Text.Trim().Replace("'", "''"));
cmd.Parameters.AddWithValue("dept_id", ddldept.SelectedValue);
cmd.Parameters.AddWithValue("Contact", txtContact.Text.Trim().Replace("'", "''"));
cmd.Transaction = tran;
cmd.ExecuteNonQuery();
tran.Commit();
}
catch
{

tran.Rollback();
con.Close();
}
finally { con.Close(); }

Bind GridView Common Function

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Master"].ConnectionString);
SqlTransaction tran=null ;
SqlCommand cmd;
SqlDataAdapter adp;
DataSet ds;

public void BindGridview(GridView gr, string table, string sorting)
{
adp = new SqlDataAdapter("Select * from " + table + " order by " + sorting ,con );
ds = new DataSet();
adp.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
gr.DataSource = ds.Tables[0];
gr.DataBind();
}
else
{ //Empty grid view
}

}

Bind DropDown Common Function

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Master"].ConnectionString);
SqlTransaction tran=null ;
SqlCommand cmd;
SqlDataAdapter adp;
DataSet ds;
public void filldropdown(DropDownList ddl, string table, string DataTextField, string DataValueField)
{
adp = new SqlDataAdapter("Select " + DataValueField + "," + DataTextField + " from " + table + " order by '" + DataTextField + "' ", con);
DataSet ds = new DataSet();
adp.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
ddl.Items.Add(ds.Tables[0].Rows[i][DataTextField].ToString());
ddl.Items[i + 1].Value = ds.Tables[0].Rows[i][DataValueField].ToString();

}
}

}

Saturday, July 3, 2010

Sum Amt and Max date of each employer

SELECT tblCustomer.Name, tblCustomer.Address, tblCustomer.Email, TblInvoice.Amt,Dateofpurchase
FROM tblCustomer INNER JOIN
TblInvoice ON tblCustomer.Cid = TblInvoice.Cid
order by TblInvoice.Cid
compute max(TblInvoice.DateOfpurchase),sum(TblInvoice.Amt) by TblInvoice.Cid