Saturday, 10 December 2011

Boxing and Unboxing

Boxing is the process of converting a value type to the type object.
e.g

int i = 123;
object o = (object)i; // boxing

Unboxing extracts the value type from the object.
o = 123;
i = (int)o; // unboxing

Tuesday, 1 November 2011

Login Code in ASP.Net using C#

using DataReader :

Sqlconnection con = new sqlconnection("your conectionstring");

Sqlcommand cmd = new sqlcommand();

cmd.commandtext = "select * from table";

cmd.connection = con;

if (con.state==connectionstate.closed) con.open();

SqlDatareader dr = cmd.executereader();

while(dr.read)

{

       if ( dr["Username"] == textbox1.text.trim() && dr["Password"] == textbox2.text )

       {

                 response.redirect("Homepage.aspx");

               return;

        }

}

Thursday, 13 October 2011

Repeater Data Binding


C# Code

SqlConnection con = new SqlConnection("Data Source=VISHAL\\SQLEXPRESS;Initial Catalog=crystal_db;Persist Security Info=True;User ID=sa;Password=sa123");
        con.Open();
       
        SqlCommand cmd = new SqlCommand("Select * from demo", con);

        cmd.CommandType = CommandType.Text;

        SqlDataAdapter adp = new SqlDataAdapter(cmd );
        DataSet dst = new DataSet();
        adp.Fill(dst);

        Repeater1.DataSource = dst;
        Repeater1.DataBind();


.aspx code



     <asp:Repeater ID="Repeater1" runat="server" >
        <HeaderTemplate >
        <table border ="1">
        <tr>
        <th>No</th>
        <th>Name</th>
       
        </tr>
        </HeaderTemplate>
        <ItemTemplate >
        <tr>
       
        <td>
        <%#DataBinder .Eval (Container .DataItem ,"No") %>
        </td>
        <td>
        <%#DataBinder .Eval (Container .DataItem ,"Name")%>
        </td>
        </ItemTemplate>
        <FooterTemplate >
        </table>
        </FooterTemplate>
        </asp:Repeater>


My First Blog

Hello world.....