Saturday, June 29, 2013

Insert Data In Sql Server(Integer Value)

ASPX.CS Page

 int Admin = ObjUser.insert_Admin(1, Convert.ToString(dropUserType.SelectedValue), Convert.ToString(txtUsername.Text));

BLL CLASS PAGE

 public int insert_Admin(int OperatorId, string UserRoll, string UserName)
       {
           SqlParameter[] param = new SqlParameter[3];

           param[0] = new SqlParameter("@OperatorId", SqlDbType.Int);
           param[0].Direction = ParameterDirection.Input;
           param[0].Value = OperatorId;

           param[1] = new SqlParameter("@UserRoll", SqlDbType.VarChar,200);
           param[1].Direction = ParameterDirection.Input;
           param[1].Value = UserRoll;

           param[2] = new SqlParameter("@UserName", SqlDbType.VarChar, 200);
           param[2].Direction = ParameterDirection.Input;
           param[2].Value = UserName;

         
                 

           int dt = objdb.Insert_Update_Del("sp_Master_User", param);

           return dt;


       }

DLL CLASS PAGE

  public Int32 Insert_Update_Del(string SP_Name, SqlParameter[] param)
        {

            DoConnection();

            SqlCommand cmd = new SqlCommand(SP_Name, Con);
            cmd.CommandType = CommandType.StoredProcedure;

            if (param.Length > 0)
            {
                for (int i = 0; i < param.Length; i++)
                {
                    cmd.Parameters.Add(param[i]);
                }
            }

            Int32 intvel = cmd.ExecuteNonQuery();
            return intvel;


        }

STORE PROCEDURE IN SQL SERVER

CREATE PROCEDURE [dbo].[sp_Master_User]
  
     @OperatorId int = NULL ,   
     @UserRoll(200) = NULL,
     @UserName(200) = NULL
    
  
    
  
AS
BEGIN
  
  
if @OperatorId = 1
begin
insert into dbo.Master_User

(
    UserRoll,
    UserName
  

)



values

(
    @UserRoll,
    @UserName
 



)
          
end   

END

calendar control in asp.net

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>






<tr>
            <td class="style2">
                Contract Start Date</td>
                                            <td>
                                                <asp:TextBox ID="TextBox17" runat="server" Width="175px"></asp:TextBox>
                                                <asp:ImageButton ID="ImageButton1" runat="server" Width="16px"
                                                    ImageUrl="~/images/Calendar.png" onclick="ImageButton1_Click" />
                                              
                                                
                                                <asp:Panel ID="Panel2" runat="server">
                                                 <asp:Calendar ID="Calendar1" runat="server" Width="80px" 
          onselectionchanged="Calendar1_SelectionChanged" ></asp:Calendar>

                                                </asp:Panel>
                                                                                              
                                                <asp:RequiredFieldValidator ID="RequiredFieldValidator17" runat="server"
                        ControlToValidate="TextBox17" ErrorMessage="Please Fill Contract Start Date" Display="Dynamic"
                                                    ValidationGroup="1"></asp:RequiredFieldValidator>
                                                 <br />
        <asp:CalendarExtender ID="calendarButtonExtender" runat="server" TargetControlID="TextBox17"
            PopupButtonID="Image1" />
                                            </td>
                                        </tr>

Thursday, June 27, 2013

Connect With Sql Server


Web Config



<appSettings>
    <add key ="ConnectDB" value ="Data Source=xxxxxx;Initial Catalog=xxxxxxxx;User ID=xxxxxxxxxxx;Password=xxxxxxxxxx"/>
   
  </appSettings>











DLL CLASS



 public class ClsDB
    {

        SqlConnection Con = new SqlConnection(ConfigurationSettings.AppSettings["ConnectDB"]);
        public void DoConnection()
        {
            if ((Con.State == ConnectionState.Closed) || (Con.State == ConnectionState.Broken))
            {
                Con.Open();
            }
        }
}