Page mypage = (Page)this.Page;
MasterPage mp = (MasterPage)mypage.Master;
Label lab = (Label)mp.FindControl("lblVersionHeader");
Wednesday, July 28, 2010
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"));
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"));
Labels:
Update Query with join
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;
}
// 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;
}
Labels:
Bind Combo Through XML
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");
//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(); }
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
}
}
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
}
}
Labels:
Bind GridView Common Function
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();
}
}
}
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();
}
}
}
Labels:
Bind DropDown Common Function
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
FROM tblCustomer INNER JOIN
TblInvoice ON tblCustomer.Cid = TblInvoice.Cid
order by TblInvoice.Cid
compute max(TblInvoice.DateOfpurchase),sum(TblInvoice.Amt) by TblInvoice.Cid
Subscribe to:
Posts (Atom)