Friday, 21 September 2012

Perform GridView Operation

   Perform GridView Operation 




Getting perticular record in Texboxes when clicked on Gridview

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Edit")
            {

                //string str = e.CommandName;
                int rowi = Convert.ToInt16(e.CommandArgument);
                GridViewRow row = GridView1.Rows[rowi];
                txtNo.Text = row.Cells[0].Text;

                txtEName.Text = row.Cells[1].Text;
                txtEmail.Text = row.Cells[2].Text;
                txtTechnology.Text = row.Cells[3].Text;
            }
       }





Delete perticular Record in gridview

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int EmpId = (int)GridView1.DataKeys[e.RowIndex].Value;


            objDBEmpManager.DeleteData(EmpId);
          
               // btnSave.Text = "Deleted";
                BindGrid();
        }


          public Boolean DeleteData(int EmpID)
        {
        objSqlCommand = new SqlCommand("USP_tDMLApp_Delete",     objSqlConnection);
            objSqlCommand.CommandType = CommandType.StoredProcedure;
            objSqlCommand.Parameters.AddWithValue("EmpId", EmpID);
            objSqlConnection.Open();
            objSqlCommand.ExecuteNonQuery();
            objSqlConnection.Close();
            return true;
        }







Get gridview value 1 page to another page trough query string




<asp:GridView ID="GridView1" runat="server" 
              AutoGenerateColumns="False" 
              DataSourceID="SqlDataSource1">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="ID,Name,Location" 
DataNavigateUrlFormatString=
"Default2.aspx?id={0}&name={1}&loc={2}" 
Text="Transfer values to other page" />
<asp:BoundField DataField="ID" HeaderText="ID" 
                SortExpression="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" 
                SortExpression="Name" />
<asp:BoundField DataField="Location" HeaderText="Location" 
                SortExpression="Location" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [ID], [Name], [Location] FROM [Details]">
</asp:SqlDataSource>

protected void Page_Load(object sender, EventArgs e)
    {
        string strID = Request.QueryString["id"];
        string strName = Request.QueryString["name"];
        string strLocation = Request.QueryString["loc"];
        lblID.Text = strID;
        lblName.Text = strName;
        lblLocation.Text = strLocation;
}   



                      Just Logic in mini Prg.


        public string Reverse(string rev)
         {
            char[] arr = rev.ToCharArray();
            Array.Reverse(arr);
            return new string(arr);
         }
        public string SortAlfabet(string rev)
        {
            char[] arr = rev.ToCharArray();
            Array.Sort<char>(arr);
            return new string(arr);
        }
        public int Count(string no)
        {
            char[] arr = no.ToCharArray();
            int res = arr.Length;
            return res;
        }

Tuesday, 4 September 2012

Difference between WCF and Web service


use cmsdev

select Id ,FName from tinfo order by FName desc,Id desc

select * from tinfo where FName=(Select * from tinfo where FName='sumit' )

select  Sum(Id) ,count(Id) as SumId from tinfo group by Fname

Select FName,Sum(Id)  from tinfo group by FName having sum(Id)<35
select top 3 Fname from tinfo

select * from tinfo where Id=(select max(Id) from tinfo) <(select max(Id)from tinfo))


select max(ID) from tinfo where id not in (select top 2 (id) from tinfo order by Id desc)

select max(ID) from tinfo where id not in (select top 1 (Id) from tinfo order by Id desc)

select * from tinfo where id=(select Max(id) from tinfo)

select distinct(CellNo) from tinfo order by CellNo asc


select * from tinfo t1 where (2)=(select count (distinct(id)) from tinfo t2 where t1.Id>t2.Id )


Difference between WCF and Web service
Web service is a part of WCF. WCF offers much more flexibility and portability to develop a service when comparing to web service. Still we are having more advantages over Web service, following table provides detailed difference between them.
Features
Web Service
WCF
Hosting
It can be hosted in IIS
It can be hosted in IIS, windows activation service, Self-hosting, Windows service
Programming
[WebService] attribute has to be added to the class
[ServiceContraact] attribute has to be added to the class
Model
[WebMethod] attribute represents the method exposed to client
[OperationContract] attribute represents the method exposed to client
Operation
One-way, Request- Response are the different operations supported in web service
One-Way, Request-Response, Duplex are different type of operations supported in WCF
XML
System.Xml.serialization name space is used for serialization
System.Runtime.Serialization namespace is used for serialization
Encoding
XML 1.0, MTOM(Message Transmission Optimization Mechanism), DIME, Custom
XML 1.0, MTOM, Binary, Custom
Transports
Can be accessed through HTTP, TCP, Custom
Can be accessed through HTTP, TCP, Named pipes, MSMQ,P2P, Custom
Protocols
Security
Security, Reliable messaging, Transactions

Monday, 3 September 2012

C# UI to XML Data Storage


C# UI to XML Data Storage



<div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><asp:TextBox ID="TextBox3"
            runat="server"></asp:TextBox><asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Insert  Data" Height="25px"
            onclick="Button1_Click" Width="80px" />
        <asp:Button ID="Button2" runat="server" Height="28px" onclick="Button2_Click"
            Text="Show Data" Width="80px" />
        <asp:Button ID="Button3" runat="server" onclick="Button3_Click"
            Text="Show XML" />
    </div>
    <asp:GridView ID="GridView1" runat="server">
    </asp:GridView>


using System.Data.SqlClient;

public partial class Xml : System.Web.UI.Page
    {
        static DataSet ds;
        static DataTable dt;
        static DataRow dr;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ds = new DataSet();
                ds.ReadXml(Server.MapPath("~/Videos.xml"));
                dt = ds.Tables["Product"];
            }
        }
        void clear()
        {
            TextBox1.Text = "";
            TextBox2.Text = "";
            TextBox3.Text = "";
            TextBox4.Text = "";

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            dr = dt.NewRow();
            dr["ProductId"] = TextBox1.Text;
            dr["Name"] = TextBox2.Text;
            dr["SmallImagePath"] = TextBox3.Text;
            dr["SmallDescreption"] = TextBox4.Text;
            dt.Rows.Add(dr);
            ds.WriteXml(Server.MapPath("~/Videos.xml"));
            Response.Write("Record Successfully Inserted");
            clear();
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            ds.ReadXml(Server.MapPath("~/Videos.xml"));
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Videos.xml");
        }


       protected void BtnRemove_Click(object sender, EventArgs e)
        {
         //   Response.Redirect("~/Videos.xml");
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(Server.MapPath("~/Videos.xml"));
            XmlNode node = xmlDoc. SelectSingleNode     ("//NewDataSet//Product[ProductID=1]");
            node.ParentNode.RemoveChild(node);
            xmlDoc.Save(Server.MapPath("~/Videos.xml"));
        }
    }
//Create Xml Like This Format
<NewDataSet>
  <Product>
    <ProductID>1</ProductID>
    <Name>Trifla</Name>
    <SmallImagePath>medohar</SmallImagePath>
    <SmallDescreption>medohar.jpg</SmallDescreption>
  </Product>
</NewDataSet>