ADS

Wednesday 27 May 2020

How to Insert Brand Record in POS ASP.NET Website with source code?

hello everyone here i will show you how to insert brand record in sql server database using Reusable code.

first create a web page and insert a textbox and 1 submit button...

for design follow video link mention below



Follow video tutorial :



double click on submit button and write following code mention below...


  using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using DBFramework;

public partial class wwwroot_Admin_Brand : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }



    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (IsFormValid ())
        {
            try
            {
                // DbSqlServer db = new DbSqlServer(AppSetting.ConnectionString());
                SaveBrandInfo("sp_Insertbrand");

                Response.Write("Record Saved Successfully");

            }
            catch(Exception ex)
            {
                Response.Write(ex.Message );
            }
        }
    }

    private void SaveBrandInfo(string storedProcName)
    {
        DbSqlServer db = new DbSqlServer(AppSetting.ConnectionString());
        db.SaveOrUpdateRecord(storedProcName, GetObject());
    }

    private object GetObject()
    {
        BrandDetails Brand = new BrandDetails();
        Brand.brand  = txtBrand .Text;
        Brand.Action  = "Insert";
        Brand.CreatedBy  = Session["user"].ToString() ;
        Brand.CreatedDate = DateTime.Today.ToShortTimeString();
        return Brand;
    }

    private bool IsFormValid()
    {
        string brand = txtBrand.Text;
        //string action = txtAction.Text;
        //string createdBy = txtcreatedby.Text;
        //string createdDate = txtcreateddate.Text;


        

        if (brand  == "" )
        {
            Response.Write("brand is Necessory ! Plz enter & try again...");
            return false;
        }
        //else if (action == "")
        //{
        //    Response.Write("action Necessory ! Plz enter action...");
        //    return false;
        //}
        //else if (createdBy  == "")
        //{
        //    Response.Write("createdby  Necessory ! Plz enter Created by...");
        //    return false;
        //}
        //else if (createdDate == "")
        //{
        //    Response.Write("createdDate Necessory ! Plz enter createdDate...");
        //    return false;
        //}
        

        return true;
    }
    public class BrandDetails
    {
        public int Id { get; set; }

        public string brand { get; set; }
        public string Action { get; set; }
        public string  CreatedBy { get; set; }
        public string CreatedDate { get; set; }

    }

}
  
  




for Full Video tutorial follow my youtube channel


thank you ...




No comments:

Post a Comment

Popular Posts