예제 #1
0
        public static balanceGetSet GetBal()
        {
            balanceGetSet bal = new balanceGetSet();


            string        strConn = @"server=localhost;Integrated Security=true;database=Bank_test";
            SqlConnection conn    = null;
            SqlCommand    comm    = null;
            SqlDataReader dr      = null;

            try
            {
                conn = new SqlConnection(strConn);
                conn.Open();

                comm             = new SqlCommand();
                comm.CommandText = "Balance";
                comm.Connection  = conn;
                comm.CommandType = CommandType.StoredProcedure;
                string s_email = Convert.ToString(HttpContext.Current.Session["currentUser"]);

                comm.Parameters.AddWithValue("@email", s_email);
                dr = comm.ExecuteReader();
                string db_fname = "";
                string db_lname = "";

                string db_type       = "";
                string db_Acc_number = "";
                string db_balance    = "";
                string db_full_name  = db_fname + " " + db_lname;


                while (dr.Read())
                {
                    db_fname      = dr[1].ToString();
                    db_lname      = dr[2].ToString();
                    db_type       = dr[4].ToString();
                    db_Acc_number = dr[0].ToString();
                    db_balance    = dr[3].ToString();
                }
                bal.account_number = db_Acc_number;
                bal.type           = db_type;
                bal.balance        = "Rs. " + db_balance;
                bal.full_name      = db_fname + " " + db_lname;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                //dr.Close();
                //comm.Cancel();
                //  conn.Close();
            }



            return(bal);
        }
        public static balanceGetSet GetBal()
        {
            balanceGetSet bal = new balanceGetSet();


            string        strConn = @"server=localhost;Integrated Security=true;database=CTS";
            SqlConnection conn    = null;
            SqlCommand    comm    = null;
            SqlDataReader dr      = null;

            try
            {
                /* conn = new SqlConnection(strConn);
                 * conn.Open();
                 *
                 * comm = new SqlCommand();
                 * comm.CommandText = "Procedure_name";
                 * comm.Connection = conn;
                 * comm.CommandType = CommandType.StoredProcedure;
                 *
                 * dr = comm.ExecuteReader();*/
                string db_fname = "Shubham";
                string db_lname = "Jadhav";

                string db_type       = "Savings Account";
                string db_Acc_number = "1010101010110101";
                string db_address    = "Vaikund Apartments, shollinagnallurn, chennai";
                string db_balance    = " 2,380";
                string db_full_name  = db_fname + " " + db_lname;

                bal.account_number = db_Acc_number;
                bal.type           = db_type;
                bal.address        = db_address;
                bal.balance        = "Rs. " + db_balance;
                bal.full_name      = db_full_name;
                while (dr.Read())
                {
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                //dr.Close();
                //comm.Cancel();
                //  conn.Close();
            }



            return(bal);

            /*string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
             * using (SqlConnection con = new SqlConnection(constr))
             * {
             *  using (SqlCommand cmd = new SqlCommand(""))
             *  {
             *      cmd.Connection = con;
             *      List<user> users = new List<user>();
             *
             *      con.Open();
             *      using (SqlDataReader sdr = cmd.ExecuteReader())
             *      {
             *          while (sdr.Read())
             *          {
             *              users.Add(new user
             *              {
             *                 CustomerId = sdr["CustomerId"].ToString(),
             *                  ContactName = sdr["ContactName"].ToString(),
             *                  City = sdr["City"].ToString(),
             *                  Country = sdr["Country"].ToString(),
             *                  PostalCode = sdr["PostalCode"].ToString(),
             *                  Phone = sdr["Phone"].ToString(),
             *                  Fax = sdr["Fax"].ToString(),
             *              });
             *          }
             *      }
             *      con.Close();
             *      return users;
             *  }
             * }*/
        }