Ejemplo n.º 1
0
        public static void insertAccounts(Account account)
        {
            List<Account> accts = new List<Account>();

            ///set the connectionstring for the db
            string dsn = ConfigurationManager.ConnectionStrings[connectionstring].ConnectionString;

            ///Layout the sql command you wish to execute
            ///
            string sqlcommand = "insert into accounts (name,date) values(@name,@date)";

            //setup the sql connecetion
            using (SqlConnection conn = new SqlConnection(dsn))
            using (SqlCommand command = new SqlCommand(sqlcommand, conn))
            {
                command.Parameters.AddWithValue("@name", account.name);
                command.Parameters.AddWithValue("@date", account.date);
                //open connection
                conn.Open();
                command.ExecuteNonQuery();
            }
        }
Ejemplo n.º 2
0
        public static void updateAccounts(Account account)
        {
            ///set the connectionstring for the db
            string dsn = ConfigurationManager.ConnectionStrings[connectionstring].ConnectionString;

            ///Layout the sql command you wish to execute
            ///
            string sqlcommand = "update accounts set name = @name , date = @date where id = @id";

            //setup the sql connecetion
            using(SqlConnection conn = new SqlConnection(dsn))
            using (SqlCommand command = new SqlCommand(sqlcommand, conn))
            {
                command.Parameters.AddWithValue("@id",account.id);
                command.Parameters.AddWithValue("@name", account.name);
                command.Parameters.AddWithValue("@date", account.date);
                //open connection
                conn.Open();
                command.ExecuteNonQuery();
            }
        }