public static List <clsCustomers> GetAllCustomers() { List <clsCustomers> x = new List <clsCustomers>(); using (SqlConnection conn = new SqlConnection(clsMain.sqlconnstring)) { conn.Open(); SqlCommand cmd = new SqlCommand("shop.spSelectAllCustomers", conn); cmd.CommandType = CommandType.StoredProcedure; SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { clsCustomers y = new clsCustomers(); y.ID = Convert.ToInt32(rdr["ID"]); y.FName = Convert.ToString(rdr["FName"]); y.SName = Convert.ToString(rdr["SName"]); y.Gender = Convert.ToString(rdr["Gender"]); y.Email = Convert.ToString(rdr["Email"]); y.Tel = Convert.ToString(rdr["Tel"]); y.City = Convert.ToString(rdr["City"]); y.CAddress = Convert.ToString(rdr["CAddress"]); y.PinCode = Convert.ToString(rdr["PinCode"]); y.Remarks = Convert.ToString(rdr["Remarks"]); y.Flag = Convert.ToString(rdr["Flag"]); x.Add(y); } } return(x); }
public static int insert(clsCustomers x) { using (SqlConnection conn = new SqlConnection(clsMain.sqlconnstring)) { conn.Open(); SqlCommand cmd = new SqlCommand("shop.spInsertCustomers", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@fn", x.FName); cmd.Parameters.AddWithValue("@sn", x.SName); cmd.Parameters.AddWithValue("@g", x.Gender); cmd.Parameters.AddWithValue("@em", x.Email); cmd.Parameters.AddWithValue("@tel", x.Tel); cmd.Parameters.AddWithValue("@city", x.City); cmd.Parameters.AddWithValue("@ca", x.CAddress); cmd.Parameters.AddWithValue("@pin", x.PinCode); cmd.Parameters.AddWithValue("@remarks", x.Remarks); cmd.Parameters.AddWithValue("@flag", x.Flag); int r = cmd.ExecuteNonQuery(); return(r); } }