Tuesday, March 15, 2011

How to use While loop in Sql Query Analyser

declare @i as int
set @i=1
BEGIN
while @i < 10

UPDATE employee_details set lastname='Kumar' where serial_num=@i
set @i=@i+1

END;

Wednesday, March 9, 2011

Convert unicode in hex

 string str = "युवराज फिर बने भारत की जीत के नायक"; //unicode text

        string data= string.Empty;  //for high performance
        foreach (char ch in str)
        {
            int temp= ch;
            data+= String.Format("{0:x4}", (uint)System.Convert.ToUInt32(temp.ToString()));
        }
        data= data.ToUpper();

Monday, February 21, 2011

How to use ajax animation extender

<style type="text/css">.flyOutDiv{display: none; position: absolute; width: 400px; z-index: 3; opacity: 0; filter: (progid: DXImageTransform.Microsoft.Alpha(opacity=0)); font-size: 18px; border: solid 1px #FFFFFF; background-color: #FFFFFF; padding
}
: 5px;.flyOutDivCloseX{background-color: #666666; color: #FFFFFF; text-align: center; font-weight: bold; text-decoration: none; border: outset thin #FFFFFF; padding
}
: 5px; </style>

Monday, February 7, 2011

How to do paging in Datalist Control in asp.net

In Design page add two link button and a data list control i.e ".aspx" page


<asp:LinkButton ID="lnkPrevious" CssClass="footertxt" runat="server" onclick="lnkPrevious_Click">Previous</asp:LinkButton>&nbsp;
<asp:LinkButton ID="lnkNext" runat="server" CssClass="footertxt" onclick="lnkNext_Click">Next</asp:LinkButton>
<asp:DataList ID="DataList1" runat="server" RepeatColumns="3"
<ItemTemplate>
"In this section add your design "
</ItemTemplate>
</asp:DataList>
 Now in .cs file write code given as :
public partial class test: System.Web.UI.Page
{
SqlDataAdapter da;
DataSet ds;
string conn;
static DataTable dt;
PagedDataSource pds;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
BindGrid();
}
public void BindGrid()
{
string conn = ConfigurationManager.ConnectionStrings["yourconnectioname"].ConnectionString;
string sql="Select * from Tbl_FreeRegister" ;
da = new SqlDataAdapter(sql, conn);
dt = new DataTable();
da.Fill(dt);
pds = new PagedDataSource();
pds.DataSource = dt.DefaultView;
pds.AllowPaging = true;
pds.PageSize = 9;
pds.CurrentPageIndex = CurrentPage;
lnkbtnPrevious.Enabled = !pds.IsFirstPage;
lnkbtnNext.Enabled = !pds.IsLastPage;
DataList1.DataSource = pds;
DataList1.DataBind();
}
//Define Property
public int CurrentPage
{
get
{
if (this.ViewState["CurrentPage"] == null)
return 0;
else
return Convert.ToInt16(this.ViewState["CurrentPage"].ToString());
}
set
{
this.ViewState["CurrentPage"] = value;
}
}
//linkbutton click event
protected void lnkPrevious_Click(object sender, EventArgs e)
{
CurrentPage -=1;
BindGrid();
}
protected void lnkNext_Click(object sender, EventArgs e)
{
CurrentPage += 1;
BindGrid();
}
}

Sunday, February 6, 2011

Select MAX no from particular column in SQL Server or MAX fuction

If we have a table design like as :




Alter table command
alter table table_name alter column membership_no int

select MAX(membership_no) as Membership from table_name





Sunday, January 30, 2011

ShutDown System By programming in asp.net

  1. using System.Management;   
  2.   
  3. public static void ShutDownComputer()   
  4. {   
  5.         ManagementBaseObject outParam = null;   
  6.         ManagementClass sysOS = new ManagementClass("Win32_OperatingSystem");   
  7.         sysOS.Get();   
  8.          
  9.         sysOS.Scope.Options.EnablePrivileges = true;    
  10.       
  11.         ManagementBaseObject inParam = sysOS.GetMethodParameters("Win32Shutdown");   
  12.        
  13.         inParam["Flags"] = "1";    
  14.         inParam["Reserved"] = "0";   
  15.         foreach (ManagementObject manObj in sysOS.GetInstances())   
  16.         {   
  17.             outParam = manObj.InvokeMethod("Win32Shutdown", inParam, null);   
  18.         }   
  19. }  

Monday, December 20, 2010

HOW TO USE XML API

 string Data = " <message-submit-request><username>abc</username><password>abc</password><sender-id>DEMO</sender-id><MType>txt</MType><message-text><text>"+txtMSG.Text+" </text><to>"+num+"</to></message-text></message-submit-request>";
string  newUrl = "http://203.129.101.201/sms/user/XML/send.php";
ApiPost(newUrl, Data);

    public string ApiPost(string url, String strPost)
    {
       try
        {







            try
            {

                ASCIIEncoding encoding = new ASCIIEncoding();



                string furl = url;

                string fmessage = "data=" + strPost;



                byte[] data = encoding.GetBytes(fmessage);



                HttpWebRequest httpreq = (HttpWebRequest)WebRequest.Create(url);

                httpreq.Method = "POST";

                httpreq.ContentType = "application/x-www-form-urlencoded";

                httpreq.ContentLength = data.Length;

                Stream newStream = httpreq.GetRequestStream();

                // Send the data.

                newStream.Write(data, 0, data.Length);







                HttpWebResponse httpres = (HttpWebResponse)httpreq.GetResponse();

                StreamReader sr = new StreamReader(httpres.GetResponseStream());



                string results = sr.ReadToEnd();

                return results;

            }

            catch
            {

                return "0";

            }



        }

        catch
        {

            return "0";

        }

    }