Monday, July 30, 2012

Declaring OUT parameter in SQL and to retrive it

public int CheckalreadyExists(string Name)
        {
            param = new SqlParameter[2];
            param[0] = new SqlParameter("@Name", Name);
            param[1] = new SqlParameter("@IsFound", SqlDbType.Int);
            param[1].Direction = ParameterDirection.Output;

            SqlHelper.ExecuteDataset(oDBConnection.ConString(), CommandType.StoredProcedure, "SPR_CheckalreadyExists", param);
            return Convert.ToInt32(param[2].Value.ToString());
        }

CREATE PROCEDURE SPR_CheckalreadyExists(
    @ID INT,   
    @IsFound TINYINT OUT
)
AS
BEGIN
    IF EXISTS(SELECT ID FROM StudentTable WHERE Name = @Name )
        BEGIN
            SET @IsFound = 1
        END
    ELSE
        BEGIN
            SET @IsFound = 0
        END
END

Wednesday, July 18, 2012

Repeater Control Sample 2

STEP 1
<asp:Repeater runat="server" ID="reptrID2">
            <HeaderTemplate>
                Data :
            </HeaderTemplate>
            <ItemTemplate>
                <%#DataBinder.Eval(Container.DataItem,"Name") %>
                (<%#DataBinder.Eval(Container.DataItem,"Age") %>)
            </ItemTemplate>
            <SeparatorTemplate>
                ,
            </SeparatorTemplate>
</asp:Repeater>

STEP 2
Just bind it....
public void FillRepeater2()
 {
    Test1BL oTest1BL = new Test1BL();
    reptrID2.DataSource = oTest1BL.GetDetails();
    reptrID2.DataBind();
  }

Repeater Control Sample 1

STEP 1
<asp:Repeater ID="reptrID" runat="server">
            <HeaderTemplate>
                <table>
                    <tr><th>Name</th><th>Age</th></tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr><td><%#DataBinder.Eval(Container.DataItem,"Name") %></td>
                    <td><%#DataBinder.Eval(Container.DataItem,"Age") %></td></tr>
            </ItemTemplate>
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:Repeater>
STEP 2
Just Bind it to DB
public void FillRepeater()
 {
    Test1BL oTest1BL = new Test1BL();
    reptrID.DataSource = oTest1BL.GetDetails();
    reptrID.DataBind();
 }

Monday, July 9, 2012

Generate random characters

public string GetRandomPasswordUsingGUID(int length)
        {
            // Get the GUID
            string guidResult = System.Guid.NewGuid().ToString();
            // Remove the hyphens
            guidResult = guidResult.Replace("-", string.Empty);
            // Make sure length is valid
            if (length <= 0 || length > guidResult.Length)
                throw new ArgumentException("Length must be between 1 and " + guidResult.Length);
            // Return the first length bytes
            return guidResult.Substring(0, length);
        }

Friday, July 6, 2012

Save file onto a folder(on solution) while upload

 //To Save the file
string test = Server.MapPath("~/Files/");
FileUpload1.PostedFile.SaveAs(test + FileUpload1.PostedFile.FileName);
//To delete the file
//add System.IO namespace for the "File" attribute
File.Delete(Server.MapPath("~/Files/" + FileUpload1.PostedFile.FileName));




<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Button" onclick="btnUpload_Click" />