Monday, 25 March 2013

how to bind database into chart control


<asp:Chart ID="Chart1" runat="server" DataSourceID="SqlDataSource1">
            <Series>
                <asp:Series Name="Series1" XValueMember="EmpName" YValueMembers="EmpID">
                </asp:Series>
            </Series>
            <ChartAreas>
                <asp:ChartArea Name="ChartArea1">
                </asp:ChartArea>
            </ChartAreas>

 </asp:Chart>


<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
            SelectCommand="SELECT top 10 [EmpName], [EmpID] FROM [tblEmployeeMaster]">
</asp:SqlDataSource>

Friday, 8 March 2013

Sql server Procedure for if Record insert first time then insert else update the table.....

I have table in which I am inserting rows for employee but next time when I want to insert row I don't want to insert again data for that employee just want to update with required columns if it exits there if not then create new row....


Syntax For Procedure:


CREATE PROCEDURE dbo.InsertOrUdpateEmployee
       @ID INT,
       
AS BEGIN
IF NOT EXISTS (SELECT * FROM Employee WHERE ID = @ID)
    INSERT INTO Employee(Col1, ..., ColN)
    VALUES(Val1, .., ValN)

ELSE

    UPDATE Employee
    SET Col1 = Val1, Col2 = Val2, ...., ColN = ValN
    WHERE ID = @ID
END